Bug 834769 - Change the "destroyed" state value for RefCounted. r=Waldo
authorMike Hommey <mh+mozilla@glandium.org>
Tue, 29 Jan 2013 09:35:16 +0100
changeset 130329 799de1cf584bf2ad61bf5724b92ca2b7d899c797
parent 130328 d7fd7fc444f67af5210e8057bc49a27ca25e7be3
child 130330 f54c2ac6248046297e602b3306653bd89da780d4
push id2323
push userbbajaj@mozilla.com
push dateMon, 01 Apr 2013 19:47:02 +0000
treeherdermozilla-beta@7712be144d91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo
bugs834769
milestone21.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 834769 - Change the "destroyed" state value for RefCounted. r=Waldo
mfbt/RefPtr.h
--- a/mfbt/RefPtr.h
+++ b/mfbt/RefPtr.h
@@ -31,40 +31,44 @@ template<typename T> OutParamRef<T> byRe
  * refcount > 0.  It's an error to allocate and free a bare
  * RefCounted<T>, i.e. outside of the RefPtr machinery.  Attempts to
  * do so will abort DEBUG builds.
  *
  * Live RefCounted<T> have refcount > 0.  The lifetime (refcounts) of
  * 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);
       ++refCnt;
     }
 
     void Release() {
       MOZ_ASSERT(refCnt > 0);
       if (0 == --refCnt) {
 #ifdef DEBUG
-        refCnt = -0xdead;
+        refCnt = dead;
 #endif
         delete static_cast<T*>(this);
       }
     }
 
     // Compatibility with wtf::RefPtr.
     void ref() { AddRef(); }
     void deref() { Release(); }