diff options
Diffstat (limited to 'src/util/pointer.h')
-rw-r--r-- | src/util/pointer.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/util/pointer.h b/src/util/pointer.h index b659cea0e..f4b70f822 100644 --- a/src/util/pointer.h +++ b/src/util/pointer.h @@ -257,3 +257,17 @@ private: unsigned int *refcount; }; +// This class is not thread-safe! +class IntrusiveReferenceCounted { +public: + IntrusiveReferenceCounted() = default; + virtual ~IntrusiveReferenceCounted() = default; + void grab() noexcept { ++m_refcount; } + void drop() noexcept { if (--m_refcount == 0) delete this; } + + // Preserve own reference count. + IntrusiveReferenceCounted(const IntrusiveReferenceCounted &) {} + IntrusiveReferenceCounted &operator=(const IntrusiveReferenceCounted &) { return *this; } +private: + u32 m_refcount = 1; +}; |