A Mutex pool.
More...
#include <yateclass.h>
A Mutex pool.
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
- Parameters
-
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) |
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
- Parameters
-
- Returns
- Valid array index
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
- Parameters
-
- Returns
- Valid Mutex pointer
References MutexPool::index().
Mutex* mutex |
( |
unsigned int |
idx | ) |
const |
|
inline |
Retrieve the mutex at a given index modulo array length
- Parameters
-
- Returns
- Valid Mutex pointer
The documentation for this class was generated from the following file: