c++-gtk-utils

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | List of all members
Cgu::IntrusiveLockCounter Class Reference
handles and smart pointers

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:

## Public Member Functions
| IntrusiveLockCounter (const IntrusiveLockCounter &)=delete
IntrusiveLockCounter & | operator= (const IntrusiveLockCounter &)=delete
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 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.

## Constructor & Destructor Documentation

Cgu::IntrusiveLockCounter::IntrusiveLockCounter | ( | const IntrusiveLockCounter & | ) |  |
| delete

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, 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.

virtual Cgu::IntrusiveLockCounter::~IntrusiveLockCounter | ( | ) |  |
| inline virtual

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

## Member Function Documentation

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

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:

- intrusive_ptr.h