#include <yateclass.h>
Public Member Functions | |
MutexPool (unsigned int len=13, bool recursive=false, const char *name=0) | |
~MutexPool () | |
unsigned int | index (void *ptr) const |
Mutex * | mutex (void *ptr) const |
Mutex * | mutex (unsigned int idx) const |
This class holds a Mutex array. Mutexes can be retrieved based on object pointers. A mutex pool can be used to associate a smaller set of Mutex objects with a much larger set of objects needing lock.
MutexPool | ( | unsigned int | len = 13 , |
|
bool | recursive = false , |
|||
const char * | name = 0 | |||
) |
Build the mutex pool
len | The number of mutex objects to build. The length should be an odd number to obtain an optimal distribution of pointer based mutexes (usually pointers are aligned at even addresses): some mutexes might never get used if the length is an even number | |
recursive | True if the mutex has to be recursive (reentrant), false for a normal fast mutex | |
name | Static name of the mutex (for debugging purpose only) |
~MutexPool | ( | ) |
Destructor. Release data
unsigned int index | ( | void * | ptr | ) | const [inline] |
Build an index from object pointer (pointer value modulo array length). Always cast the pointer to the same type when calling this method to make sure the same index is returned for a given object
ptr | The pointer to object |
Referenced by MutexPool::mutex().
Mutex* mutex | ( | void * | ptr | ) | const [inline] |
Retrieve the mutex associated with a given pointer. Always cast the pointer to the same type when calling this method to make sure the same mutex is returned for a given object
ptr | The pointer to object |
References MutexPool::index().
Mutex* mutex | ( | unsigned int | idx | ) | const [inline] |
Retrieve the mutex at a given index modulo array length
idx | The index |