3 #include <CesiumUtility/Assert.h>
20 std::thread::id _threadID;
47 template <
typename T,
bool isThreadSafe = true>
64 if constexpr (!isThreadSafe) {
65 CESIUM_ASSERT(std::this_thread::get_id() == this->_threadID);
69 ++this->_referenceCount;
80 if constexpr (!isThreadSafe) {
81 CESIUM_ASSERT(std::this_thread::get_id() == this->_threadID);
85 CESIUM_ASSERT(this->_referenceCount > 0);
86 const int32_t references = --this->_referenceCount;
87 if (references == 0) {
88 delete static_cast<const T*
>(
this);
96 return this->_referenceCount;
100 using ThreadSafeCounter = std::atomic<std::int32_t>;
101 using NonThreadSafeCounter = std::int32_t;
103 std::conditional_t<isThreadSafe, ThreadSafeCounter, NonThreadSafeCounter>;
105 mutable CounterType _referenceCount{0};
118 template <
typename T>
131 template <
typename T>
A reference-counted base class, meant to be used with IntrusivePointer.
std::int32_t getReferenceCount() const noexcept
Returns the current reference count of this instance.
void releaseReference() const
Removes a counted reference from this object. When the last reference is removed, this method will de...
void addReference() const
Adds a counted reference to this object. Use CesiumUtility::IntrusivePointer instead of calling this ...
Utility classes for Cesium.