Yate
RWLockPool Class Reference

A RWLock pool. More...

#include <yateclass.h>

Public Member Functions

 RWLockPool (unsigned int len=13, const char *name=0)
 
 ~RWLockPool ()
 
unsigned int index (void *ptr) const
 
RWLocklock (void *ptr) const
 
RWLocklock (unsigned int idx) const
 

Detailed Description

A RWLock pool.

This class holds a RWLock array. Locks can be retrieved based on object pointers. A lock pool can be used to associate a smaller set of RWLock objects with a much larger set of objects needing lock.

Constructor & Destructor Documentation

◆ RWLockPool()

RWLockPool ( unsigned int len = 13,
const char * name = 0 )

Build the lock pool

Parameters
lenThe number of lock objects to build. The length should be an odd number to obtain an optimal distribution of pointer based locks (usually pointers are aligned at even addresses): some locks might never get used if the length is an even number
nameStatic name of the lock (for debugging purpose only)

◆ ~RWLockPool()

~RWLockPool ( )

Destructor. Release data

Member Function Documentation

◆ index()

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

◆ lock() [1/2]

RWLock * lock ( unsigned int idx) const
inline

Retrieve the lock at a given index modulo array length

Parameters
idxThe index
Returns
Valid RWLock pointer

◆ lock() [2/2]

RWLock * lock ( void * ptr) const
inline

Retrieve the lock associated with a given pointer. Always cast the pointer to the same type when calling this method to make sure the same lock is returned for a given object

Parameters
ptrThe pointer to object
Returns
Valid RWLock pointer

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