[llvm-commits] [llvm] r128804 - /llvm/trunk/include/llvm/ADT/IntrusiveRefCntPtr.h

Peter Collingbourne peter at pcc.me.uk
Sun Apr 3 17:57:03 PDT 2011


Author: pcc
Date: Sun Apr  3 19:57:03 2011
New Revision: 128804

URL: http://llvm.org/viewvc/llvm-project?rev=128804&view=rev
Log:
IntrusiveRefCntPtr: in RefCountedBase and RefCountedBaseVPTR, make
ref_cnt mutable and Retain/Release const to enable reference counted
pointers to const objects

Modified:
    llvm/trunk/include/llvm/ADT/IntrusiveRefCntPtr.h

Modified: llvm/trunk/include/llvm/ADT/IntrusiveRefCntPtr.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/IntrusiveRefCntPtr.h?rev=128804&r1=128803&r2=128804&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/IntrusiveRefCntPtr.h (original)
+++ llvm/trunk/include/llvm/ADT/IntrusiveRefCntPtr.h Sun Apr  3 19:57:03 2011
@@ -42,15 +42,15 @@
 //===----------------------------------------------------------------------===//
   template <class Derived>
   class RefCountedBase {
-    unsigned ref_cnt;
+    mutable unsigned ref_cnt;
 
   public:
     RefCountedBase() : ref_cnt(0) {}
 
-    void Retain() { ++ref_cnt; }
-    void Release() {
+    void Retain() const { ++ref_cnt; }
+    void Release() const {
       assert (ref_cnt > 0 && "Reference count is already zero.");
-      if (--ref_cnt == 0) delete static_cast<Derived*>(this);
+      if (--ref_cnt == 0) delete static_cast<const Derived*>(this);
     }
   };
 
@@ -63,14 +63,14 @@
 ///  attempting to do this will produce a compile error.
 //===----------------------------------------------------------------------===//
   class RefCountedBaseVPTR {
-    unsigned ref_cnt;
+    mutable unsigned ref_cnt;
 
   protected:
     RefCountedBaseVPTR() : ref_cnt(0) {}
     virtual ~RefCountedBaseVPTR() {}
 
-    void Retain() { ++ref_cnt; }
-    void Release() {
+    void Retain() const { ++ref_cnt; }
+    void Release() const {
       assert (ref_cnt > 0 && "Reference count is already zero.");
       if (--ref_cnt == 0) delete this;
     }





More information about the llvm-commits mailing list