Bug 912299 - Make RefCounted's refcount field mutable. r=waldo
authorSeth Fowler <seth@mozilla.com>
Fri, 06 Sep 2013 13:32:55 -0700
changeset 146021 e2796e169e2834986d2c341ecca63e42de81e333
parent 146020 cdb9d968f5573f5138dbce26a6395ff0122abbe2
child 146022 74b3812bad143d0e62573cb691928cf793ef2bd1
push id2538
push userryanvm@gmail.com
push dateSat, 07 Sep 2013 01:11:25 +0000
treeherderfx-team@3697f962bb7b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswaldo
bugs912299
milestone26.0a1
Bug 912299 - Make RefCounted's refcount field mutable. r=waldo
mfbt/RefPtr.h
mozglue/linker/ElfLoader.h
--- a/mfbt/RefPtr.h
+++ b/mfbt/RefPtr.h
@@ -63,42 +63,42 @@ class RefCounted
   protected:
     RefCounted() : refCnt(0) { }
     ~RefCounted() {
       MOZ_ASSERT(refCnt == detail::DEAD);
     }
 
   public:
     // Compatibility with nsRefPtr.
-    void AddRef() {
+    void AddRef() const {
       MOZ_ASSERT(refCnt >= 0);
       ++refCnt;
     }
 
-    void Release() {
+    void Release() const {
       MOZ_ASSERT(refCnt > 0);
       if (0 == --refCnt) {
 #ifdef DEBUG
         refCnt = detail::DEAD;
 #endif
-        delete static_cast<T*>(this);
+        delete static_cast<const T*>(this);
       }
     }
 
     // Compatibility with wtf::RefPtr.
     void ref() { AddRef(); }
     void deref() { Release(); }
     int refCount() const { return refCnt; }
     bool hasOneRef() const {
       MOZ_ASSERT(refCnt > 0);
       return refCnt == 1;
     }
 
   private:
-    typename Conditional<Atomicity == AtomicRefCount, Atomic<int>, int>::Type refCnt;
+    mutable typename Conditional<Atomicity == AtomicRefCount, Atomic<int>, int>::Type refCnt;
 };
 
 }
 
 template<typename T>
 class RefCounted : public detail::RefCounted<T, detail::NonAtomicRefCount>
 {
   public:
--- a/mozglue/linker/ElfLoader.h
+++ b/mozglue/linker/ElfLoader.h
@@ -65,17 +65,17 @@ IsSignalHandlingBroken();
  * RefCounted<LibHandle>::Release to support some reentrancy. See further
  * below.
  */
 class LibHandle;
 
 namespace mozilla {
 namespace detail {
 
-template <> inline void RefCounted<LibHandle, AtomicRefCount>::Release();
+template <> inline void RefCounted<LibHandle, AtomicRefCount>::Release() const;
 
 template <> inline RefCounted<LibHandle, AtomicRefCount>::~RefCounted()
 {
   MOZ_ASSERT(refCnt == 0x7fffdead);
 }
 
 } /* namespace detail */
 } /* namespace mozilla */
@@ -210,30 +210,30 @@ private:
  * to 1 on normal builds, and 0x7fffdead on debug builds so that the LibHandle
  * can still be referenced while the destructor is executing. The refCnt is
  * allowed to grow > 0x7fffdead, but not to decrease under that value, which
  * would mean too many Releases from within the destructor.
  */
 namespace mozilla {
 namespace detail {
 
-template <> inline void RefCounted<LibHandle, AtomicRefCount>::Release() {
+template <> inline void RefCounted<LibHandle, AtomicRefCount>::Release() const {
 #ifdef DEBUG
   if (refCnt > 0x7fff0000)
     MOZ_ASSERT(refCnt > 0x7fffdead);
 #endif
   MOZ_ASSERT(refCnt > 0);
   if (refCnt > 0) {
     if (0 == --refCnt) {
 #ifdef DEBUG
       refCnt = 0x7fffdead;
 #else
       refCnt = 1;
 #endif
-      delete static_cast<LibHandle*>(this);
+      delete static_cast<const LibHandle*>(this);
     }
   }
 }
 
 } /* namespace detail */
 } /* namespace mozilla */
 
 /**