39 #ifndef CGU_INTRUSIVE_PTR_H
40 #define CGU_INTRUSIVE_PTR_H
51 #ifdef CGU_INTRUSIVE_LOCK_COUNTER_USE_MUTEX
103 if (obj_p) obj_p->unref();
107 if (obj_p) obj_p->ref();
132 obj_p = intr_ptr.obj_p;
141 obj_p = intr_ptr.obj_p;
158 obj_p = intr_ptr.obj_p;
170 obj_p = intr_ptr.obj_p;
220 T*
get()
const noexcept {
return obj_p;}
292 void ref() noexcept {++count;}
302 if (count == 0)
delete this;
350 #ifdef CGU_INTRUSIVE_LOCK_COUNTER_USE_MUTEX
379 #ifdef CGU_INTRUSIVE_LOCK_COUNTER_USE_MUTEX
383 g_atomic_int_inc(&count);
394 #ifdef CGU_INTRUSIVE_LOCK_COUNTER_USE_MUTEX
403 if (g_atomic_int_dec_and_test(&count)) {
430 #if defined(CGU_USE_SMART_PTR_COMPARISON) || defined(DOXYGEN_PARSING)
444 return (s1.get() == s2.get());
476 return std::less<T*>()(s1.get(), s2.get());
479 #endif // CGU_USE_SMART_PTR_COMPARISON
486 #if defined(CGU_USE_SMART_PTR_COMPARISON) && !defined(DOXYGEN_PARSING)
491 struct hash<
Cgu::IntrusivePtr<T>> {
492 typedef std::size_t result_type;
494 result_type operator()(
const argument_type& s)
const {
502 #endif // CGU_USE_SMART_PTR_COMPARISON
IntrusivePtr & operator=(IntrusivePtr< U > &&intr_ptr)
Definition: intrusive_ptr.h:211
bool operator!=(const GobjHandle< T > &h1, const GobjHandle< T > &h2) noexcept
Definition: gobj_handle.h:613
IntrusiveLockCounter()
Definition: intrusive_ptr.h:421
int lock() noexcept
Definition: mutex.h:147
IntrusiveCounter & operator=(const IntrusiveCounter &)=delete
IntrusivePtr(T *ptr=0)
Definition: intrusive_ptr.h:119
void ref() noexcept
Definition: intrusive_ptr.h:378
IntrusivePtr(const IntrusivePtr &intr_ptr)
Definition: intrusive_ptr.h:131
T * operator->() const noexcept
Definition: intrusive_ptr.h:233
void swap(Cgu::AsyncQueue< T, Container > &q1, Cgu::AsyncQueue< T, Container > &q2)
Definition: async_queue.h:1483
IntrusivePtr(IntrusivePtr &&intr_ptr) noexcept
Definition: intrusive_ptr.h:140
IntrusivePtr(const IntrusivePtr< U > &intr_ptr)
Definition: intrusive_ptr.h:157
~IntrusivePtr()
Definition: intrusive_ptr.h:253
int unlock() noexcept
Definition: mutex.h:170
IntrusivePtr & operator=(const IntrusivePtr< U > &intr_ptr)
Definition: intrusive_ptr.h:198
This is a counter class providing the ref() and unref() functions required by IntrusivePtr.
Definition: intrusive_ptr.h:268
bool operator==(const GobjHandle< T > &h1, const GobjHandle< T > &h2) noexcept
Definition: gobj_handle.h:600
A specialization of std::hash for Cgu::Callback::FunctorArg, Cgu::Callback::SafeFunctorArg, Cgu::GobjHandle, Cgu::GvarHandle, Cgu::IntrusivePtr, Cgu::SharedHandle, Cgu::SharedLockHandle, Cgu::SharedPtr and Cgu::SharedLockPtr so that such objects may be keys of unordered associative containers.
This is a smart pointer for managing objects allocated on freestore which maintain their own referenc...
Definition: intrusive_ptr.h:98
A scoped locking class for exception safe Mutex locking.
Definition: mutex.h:207
A wrapper class for pthread mutexes.
Definition: mutex.h:117
T & operator*() const noexcept
Definition: intrusive_ptr.h:226
This is a counter class providing the ref() and unref() functions required by IntrusivePtr, with a thread safe reference count..
Definition: intrusive_ptr.h:349
void reset(T *ptr=0)
Definition: intrusive_ptr.h:244
Provides wrapper classes for pthread mutexes and condition variables, and scoped locking classes for ...
Definition: application.h:44
IntrusivePtr(IntrusivePtr< U > &&intr_ptr) noexcept
Definition: intrusive_ptr.h:169
void unref()
Definition: intrusive_ptr.h:300
IntrusiveLockCounter & operator=(const IntrusiveLockCounter &)=delete
virtual ~IntrusiveLockCounter()
Definition: intrusive_ptr.h:427
virtual ~IntrusiveCounter()
Definition: intrusive_ptr.h:314
void ref() noexcept
Definition: intrusive_ptr.h:292
IntrusiveCounter() noexcept
Definition: intrusive_ptr.h:308
friend class IntrusivePtr
Definition: intrusive_ptr.h:145
IntrusivePtr & operator=(IntrusivePtr intr_ptr)
Definition: intrusive_ptr.h:184
void unref()
Definition: intrusive_ptr.h:393