Bug 834769 - Change the "destroyed" state value for RefCounted. r=Waldo
☠☠ backed out by 954fc89373b8 ☠ ☠
authorMike Hommey <mh+mozilla@glandium.org>
Tue, 29 Jan 2013 09:35:16 +0100
changeset 130044 bc2bbe9836c7c40eedca35e79d4f73974736e20d
parent 130043 a24051aa1b468405d4c474c324941007cfd037ca
child 130045 4631eeae9ff4505721dffb0fc4f65b395e4a73ae
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,41 @@ 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:
+  protected:
     RefCounted() : refCnt(0) { }
-    ~RefCounted() { MOZ_ASSERT(refCnt == -0xdead); }
+    ~RefCounted() { MOZ_ASSERT(refCnt == 0xffffdead); }
 
+  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 = 0xffffdead;
 #endif
         delete static_cast<T*>(this);
       }
     }
 
     // Compatibility with wtf::RefPtr.
     void ref() { AddRef(); }
     void deref() { Release(); }