llvm.org GIT mirror llvm / 10fdd5a
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 Peter Collingbourne 9 years ago
1 changed file(s) with 7 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
4141 //===----------------------------------------------------------------------===//
4242 template
4343 class RefCountedBase {
44 unsigned ref_cnt;
44 mutable unsigned ref_cnt;
4545
4646 public:
4747 RefCountedBase() : ref_cnt(0) {}
4848
49 void Retain() { ++ref_cnt; }
50 void Release() {
49 void Retain() const { ++ref_cnt; }
50 void Release() const {
5151 assert (ref_cnt > 0 && "Reference count is already zero.");
52 if (--ref_cnt == 0) delete static_cast<Derived*>(this);
52 if (--ref_cnt == 0) delete static_cast<const Derived*>(this);
5353 }
5454 };
5555
6262 /// attempting to do this will produce a compile error.
6363 //===----------------------------------------------------------------------===//
6464 class RefCountedBaseVPTR {
65 unsigned ref_cnt;
65 mutable unsigned ref_cnt;
6666
6767 protected:
6868 RefCountedBaseVPTR() : ref_cnt(0) {}
6969 virtual ~RefCountedBaseVPTR() {}
7070
71 void Retain() { ++ref_cnt; }
72 void Release() {
71 void Retain() const { ++ref_cnt; }
72 void Release() const {
7373 assert (ref_cnt > 0 && "Reference count is already zero.");
7474 if (--ref_cnt == 0) delete this;
7575 }