This is a counter class providing the ref() and unref() functions required by IntrusivePtr, with a thread safe reference count..
- See also
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 synchronization 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, the symbol CGU_INTRUSIVE_LOCK_COUNTER_USE_MUTEX can be defined so that the library uses mutexes instead, which might be useful for some debugging purposes. Note that if CGU_INTRUSIVE_LOCK_COUNTER_USE_MUTEX is to be defined, this is best done by textually amending the intrusive_ptr.h header file before the library is compiled. This will ensure that everything in the program and the library which includes the intrusive_ptr.h header is guaranteed to see the same definitions so that the C++ standard's one-definition-rule is complied with.
By default, glib atomic functions are used to provide thread-safe manipulation of the reference count. However, the header file intrusive_ptr.h can be textually amended before the library is compiled to define the symbol CGU_INTRUSIVE_LOCK_COUNTER_USE_MUTEX so as to use mutexes instead, which might be useful for some debugging purposes. Were that to be done, Cgu::Thread::MutexError might be thrown by this constructor if initialization of the mutex fails.
Otherwise, this constructor does not throw.