#include <counted.h>

Call AcquirePointer method to get counted pointer to this object. Deleting by delete operator is not allowed, use Release method instead. AcquirePointer can return NULL if object has been deleted from another thread in the same time.
Object is not deleted from memory until number of pointers is zero. This is usefull if you want to be sure that your object still exists.
This class is thread-safe execpt one case - the absotelly last deleted object. It must be deleted safetely from one thread and no other thread can acquire pointer simultaneously. This is provided by root node in KernelServer in our engine.
Usage example:
Counted *p = new Counted(); // create object (first conted pointer is set) Counted *cp1 = p->AcquirePointer(); // get next counted pointer Counted *cp2 = p->AcquirePointer(); // get another counted opinter p->Release(); // object is not deleted from memory, only number of counted pointers is decreased cp1->Release(); // object still exists cp2->Release(); // now the object is deleted from memory
Public Member Functions | |
| Counted () | |
| Counted * | AcquirePointer () |
| virtual bool | Release () |
Protected Member Functions | |
| virtual | ~Counted () |
Static Protected Member Functions | |
| static void | LockCounted () |
| static void | UnlockCounted () |
Private Attributes | |
| uint_t | pointers_count |
| Number of pointers to this object. | |
Static Private Attributes | |
| static uint_t | instances_count = 0 |
| Number of all instances of Counted object. | |
| static Mutex * | counted_mutex = NULL |
| Mutex for changing pointers count. | |
| Counted::Counted | ( | ) | [inline] |
| Counted::~Counted | ( | ) | [inline, protected, virtual] |
| Counted * Counted::AcquirePointer | ( | ) | [inline] |
| bool Counted::Release | ( | ) | [inline, virtual] |
| void Counted::LockCounted | ( | ) | [inline, static, protected] |
| void Counted::UnlockCounted | ( | ) | [inline, static, protected] |
uint_t Counted::pointers_count [private] |
Number of pointers to this object.
uint_t Counted::instances_count = 0 [static, private] |
Number of all instances of Counted object.
Mutex * Counted::counted_mutex = NULL [static, private] |
Mutex for changing pointers count.
1.5.3