aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2011-04-04 00:57:03 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2011-04-04 00:57:03 +0000
commit10fdd5a0f622bdea4003ffa818eeb9486bfb0730 (patch)
treee35b9bccbdb92b852a53599ad49a6becc8bb681d
parenteeb7f4ce2dca47453d5e39448a4aa61c1c7d72d1 (diff)
IntrusiveRefCntPtr: in RefCountedBase and RefCountedBaseVPTR, make
ref_cnt mutable and Retain/Release const to enable reference counted pointers to const objects git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128804 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/ADT/IntrusiveRefCntPtr.h14
1 files changed, 7 insertions, 7 deletions
diff --git a/include/llvm/ADT/IntrusiveRefCntPtr.h b/include/llvm/ADT/IntrusiveRefCntPtr.h
index 592e42f7ad..2f6fd2bd55 100644
--- a/include/llvm/ADT/IntrusiveRefCntPtr.h
+++ b/include/llvm/ADT/IntrusiveRefCntPtr.h
@@ -42,15 +42,15 @@ namespace llvm {
//===----------------------------------------------------------------------===//
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 @@ namespace llvm {
/// 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;
}