c++-gtk-utils
Public Member Functions
Cgu::IntrusiveLockCounter Class Reference

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>

Inheritance diagram for Cgu::IntrusiveLockCounter:
Cgu::FilePrintManager Cgu::TextPrintManager Cgu::Thread::Future< Val >

List of all members.

Public Member Functions

 IntrusiveLockCounter (const IntrusiveLockCounter &)
IntrusiveLockCounteroperator= (const IntrusiveLockCounter &)
void ref ()
void unref ()
 IntrusiveLockCounter ()
virtual ~IntrusiveLockCounter ()

Detailed Description

This is a counter class providing the ref() and unref() functions required by IntrusivePtr, with a thread safe reference count..

See also:
IntrusiveCounter.

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.


Constructor & Destructor Documentation

Cgu::IntrusiveLockCounter::IntrusiveLockCounter ( const IntrusiveLockCounter )

This class cannot be copied. The copy constructor is deleted.

Cgu::IntrusiveLockCounter::IntrusiveLockCounter ( )
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.

virtual Cgu::IntrusiveLockCounter::~IntrusiveLockCounter ( )
inlinevirtual

This destructor does not throw, unless the destructor of a derived class throws.


Member Function Documentation

IntrusiveLockCounter& Cgu::IntrusiveLockCounter::operator= ( const IntrusiveLockCounter )

This class cannot be copied. The assignment operator is deleted.

void Cgu::IntrusiveLockCounter::ref ( )
inline

Increments the reference count. This method does not throw.

void Cgu::IntrusiveLockCounter::unref ( )
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.


The documentation for this class was generated from the following file: