mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-21 01:37:16 +00:00
Bug 834769 - Change the "destroyed" state value for RefCounted. r=Waldo
This commit is contained in:
parent
6364ff2403
commit
19f90e4909
@ -36,19 +36,20 @@ template<typename T> OutParamRef<T> byRef(RefPtr<T>&);
|
||||
* live RefCounted<T> are controlled by RefPtr<T> and
|
||||
* RefPtr<super/subclass of T>. Upon a transition from refcounted==1
|
||||
* to 0, the RefCounted<T> "dies" and is destroyed. The "destroyed"
|
||||
* state is represented in DEBUG builds by refcount==-0xdead. This
|
||||
* state is represented in DEBUG builds by refcount==0xffffdead. This
|
||||
* state distinguishes use-before-ref (refcount==0) from
|
||||
* use-after-destroy (refcount==-0xdead).
|
||||
* use-after-destroy (refcount==0xffffdead).
|
||||
*/
|
||||
template<typename T>
|
||||
class RefCounted
|
||||
{
|
||||
friend class RefPtr<T>;
|
||||
|
||||
public:
|
||||
protected:
|
||||
RefCounted() : refCnt(0) { }
|
||||
~RefCounted() { MOZ_ASSERT(refCnt == -0xdead); }
|
||||
~RefCounted() { MOZ_ASSERT(refCnt == 0xffffdead); }
|
||||
|
||||
public:
|
||||
// Compatibility with nsRefPtr.
|
||||
void AddRef() {
|
||||
MOZ_ASSERT(refCnt >= 0);
|
||||
@ -59,7 +60,7 @@ class RefCounted
|
||||
MOZ_ASSERT(refCnt > 0);
|
||||
if (0 == --refCnt) {
|
||||
#ifdef DEBUG
|
||||
refCnt = -0xdead;
|
||||
refCnt = 0xffffdead;
|
||||
#endif
|
||||
delete static_cast<T*>(this);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user