Bug 834769 - Change the "destroyed" state value for RefCounted. r=Waldo

This commit is contained in:
Mike Hommey 2013-01-29 09:35:16 +01:00
Родитель df70168a14
Коммит 66cbfc73f8
1 изменённых файлов: 9 добавлений и 5 удалений

Просмотреть файл

@ -36,19 +36,23 @@ 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:
#ifdef DEBUG
static const int dead = 0xffffdead;
#endif
protected:
RefCounted() : refCnt(0) { }
~RefCounted() { MOZ_ASSERT(refCnt == -0xdead); }
~RefCounted() { MOZ_ASSERT(refCnt == dead); }
public:
// Compatibility with nsRefPtr.
void AddRef() {
MOZ_ASSERT(refCnt >= 0);
@ -59,7 +63,7 @@ class RefCounted
MOZ_ASSERT(refCnt > 0);
if (0 == --refCnt) {
#ifdef DEBUG
refCnt = -0xdead;
refCnt = dead;
#endif
delete static_cast<T*>(this);
}