c++-gtk-utils
|
This is a counter class providing the ref() and unref() functions required by IntrusivePtr, with a thread safe reference count.. More...
#include <c++-gtk-utils/intrusive_ptr.h>
Public Member Functions | |
IntrusiveLockCounter (const IntrusiveLockCounter &) | |
IntrusiveLockCounter & | operator= (const IntrusiveLockCounter &) |
void | ref () |
void | unref () |
IntrusiveLockCounter () | |
virtual | ~IntrusiveLockCounter () |
This is a counter class providing the ref() and unref() functions required by IntrusivePtr, with a thread safe reference count..
This is a counter class providing the ref() and unref() functions required by IntrusivePtr. It is intended to be inherited from by classes which are to be managed by such a smart pointer, and includes locking so that such an inheriting class object can be accessed by different IntrusivePtr objects in different threads (although the word Lock is in the title, by default it uses glib atomic functions to access the reference count rather than a mutex, so the overhead should be very small). Note that only the reference count is protected, so this is thread safe in the sense in which a raw pointer is thread safe.
As mentioned, by default glib atomic functions are used to provide thread-safe manipulation of the reference count. However, a library user can define the symbol CGU_INTRUSIVE_LOCK_COUNTER_USE_MUTEX before this file is parsed so as to use mutexes instead, which might be useful for some debugging purposes.
Cgu::IntrusiveLockCounter::IntrusiveLockCounter | ( | const IntrusiveLockCounter & | ) |
This class cannot be copied. The copy constructor is deleted.
|
inline |
By default, glib atomic functions are used to provide thread-safe manipulation of the reference count. However, from version 1.2.0 a library user can define the symbol CGU_INTRUSIVE_LOCK_COUNTER_USE_MUTEX before this file is parsed so as to use mutexes instead, which might be useful for some debugging purposes. Were she to do so, Cgu::Thread::MutexError might be thrown by this constructor if initialization of the mutex fails, but it is usually not worth checking for this.
Otherwise, this constructor does not throw.
|
inlinevirtual |
This destructor does not throw, unless the destructor of a derived class throws.
IntrusiveLockCounter& Cgu::IntrusiveLockCounter::operator= | ( | const IntrusiveLockCounter & | ) |
This class cannot be copied. The assignment operator is deleted.
|
inline |
Increments the reference count. This method does not throw.
|
inline |
Decrements the reference count, and if the count reaches 0 deletes itself (ie the managed object). This method does not throw unless the destructor of a derived class throws - that should never happen.