56 #ifndef WPIUTIL_WPI_INTRUSIVEREFCNTPTR_H 57 #define WPIUTIL_WPI_INTRUSIVEREFCNTPTR_H 72 mutable unsigned RefCount = 0;
78 void Retain()
const { ++RefCount; }
80 void Release()
const {
81 assert(RefCount > 0 &&
"Reference count is already zero.");
83 delete static_cast<const Derived *
>(
this);
89 mutable std::atomic<int> RefCount;
95 void Retain()
const { RefCount.fetch_add(1, std::memory_order_relaxed); }
97 void Release()
const {
98 int NewRefCount = RefCount.fetch_sub(1, std::memory_order_acq_rel) - 1;
99 assert(NewRefCount >= 0 &&
"Reference count was already zero.");
100 if (NewRefCount == 0)
101 delete static_cast<const Derived *
>(
this);
126 static void retain(T *obj) { obj->Retain(); }
127 static void release(T *obj) { obj->Release(); }
140 using element_type = T;
164 T &operator*()
const {
return *Obj; }
165 T *operator->()
const {
return Obj; }
166 T *
get()
const {
return Obj; }
167 explicit operator bool()
const {
return Obj; }
180 void resetWithoutRelease() { Obj =
nullptr; }
196 template <
class T,
class U>
199 return A.get() == B.get();
202 template <
class T,
class U>
205 return A.get() != B.get();
208 template <
class T,
class U>
213 template <
class T,
class U>
218 template <
class T,
class U>
223 template <
class T,
class U>
253 using SimpleType = T *;
261 using SimpleType = T *;
270 #endif // LLVM_ADT_INTRUSIVEREFCNTPTR_H A smart pointer to a reference-counted object that inherits from RefCountedBase or ThreadSafeRefCount...
Definition: IntrusiveRefCntPtr.h:136
namespace to hold default to_json function
Definition: json_binary_writer.cpp:39
Definition: IntrusiveRefCntPtr.h:250
Class you can specialize to provide custom retain/release functionality for a type.
Definition: IntrusiveRefCntPtr.h:125
A thread-safe version of RefCountedBase.
Definition: IntrusiveRefCntPtr.h:88
A CRTP mixin class that adds reference counting to a type.
Definition: IntrusiveRefCntPtr.h:71
bool operator==(json::const_reference lhs, json::const_reference rhs) noexcept
Definition: json.cpp:921