Yate
Public Member Functions
MutexPool Class Reference

A Mutex pool. More...

#include <yateclass.h>

List of all members.

Public Member Functions

 MutexPool (unsigned int len=13, bool recursive=false, const char *name=0)
 ~MutexPool ()
unsigned int index (void *ptr) const
Mutexmutex (void *ptr) const
Mutexmutex (unsigned int idx) const

Detailed Description

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.


Constructor & Destructor Documentation

MutexPool ( unsigned int  len = 13,
bool  recursive = false,
const char *  name = 0 
)

Build the mutex pool

Parameters:
lenThe 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
recursiveTrue if the mutex has to be recursive (reentrant), false for a normal fast mutex
nameStatic name of the mutex (for debugging purpose only)
~MutexPool ( )

Destructor. Release data


Member Function Documentation

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:
ptrThe pointer to object
Returns:
Valid array index
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:
ptrThe pointer to object
Returns:
Valid Mutex pointer
Mutex* mutex ( unsigned int  idx) const [inline]

Retrieve the mutex at a given index modulo array length

Parameters:
idxThe index
Returns:
Valid Mutex pointer

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