21 #ifndef LLVM_ADT_INTRUSIVEREFCNTPTR_H 22 #define LLVM_ADT_INTRUSIVEREFCNTPTR_H 43 template <
class Derived>
45 mutable unsigned ref_cnt;
51 void Retain()
const { ++ref_cnt; }
52 void Release()
const {
53 assert (ref_cnt > 0 &&
"Reference count is already zero.");
54 if (--ref_cnt == 0)
delete static_cast<const Derived*
>(
this);
67 mutable unsigned ref_cnt;
68 virtual void anchor();
76 void Retain()
const { ++ref_cnt; }
77 void Release()
const {
78 assert (ref_cnt > 0 &&
"Reference count is already zero.");
79 if (--ref_cnt == 0)
delete this;
88 static void retain(T *obj) { obj->Retain(); }
89 static void release(T *obj) { obj->Release(); }
99 template <
class Derived>
101 mutable std::atomic<int> RefCount;
107 void Retain()
const { ++RefCount; }
109 void Release()
const {
110 int NewRefCount = --RefCount;
111 assert(NewRefCount >= 0 &&
"Reference count was already zero.");
112 if (NewRefCount == 0)
113 delete static_cast<const Derived*
>(
this);
134 template <
typename T>
139 typedef T element_type;
173 T& operator*()
const {
return *Obj; }
175 T* operator->()
const {
return Obj; }
177 T*
get()
const {
return Obj; }
179 explicit operator bool()
const {
return Obj; }
192 void resetWithoutRelease() {
200 template <
typename X>
204 template<
class T,
class U>
208 return A.get() == B.get();
211 template<
class T,
class U>
215 return A.get() != B.get();
218 template<
class T,
class U>
225 template<
class T,
class U>
232 template<
class T,
class U>
233 inline bool operator==(T* A,
239 template<
class T,
class U>
240 inline bool operator!=(T* A,
273 typedef T* SimpleType;
280 typedef T* SimpleType;
288 #endif // LLVM_ADT_INTRUSIVEREFCNTPTR_H
Definition: IntrusiveRefCntPtr.h:87
RefCountedBase - A generic base class for objects that wish to have their lifetimes managed using ref...
Definition: IntrusiveRefCntPtr.h:44
Definition: IntrusiveRefCntPtr.h:270
IntrusiveRefCntPtr - A template class that implements a "smart pointer" that assumes the wrapped obje...
Definition: IntrusiveRefCntPtr.h:31
RefCountedBaseVPTR - A class that has the same function as RefCountedBase, but with a virtual destruc...
Definition: IntrusiveRefCntPtr.h:66
A thread-safe version of llvm::RefCountedBase.
Definition: IntrusiveRefCntPtr.h:100