PReadWriteMutex Class Reference

#include <syncthrd.h>

Inheritance diagram for PReadWriteMutex:

PObject List of all members.

Public Member Functions

Operations
void StartRead ()
void EndRead ()
void StartWrite ()
void EndWrite ()

Protected Member Functions

NestGetNest () const
NestStartNest ()
void EndNest ()
void InternalStartRead ()
void InternalEndRead ()

Protected Attributes

PSemaphore readerSemaphore
PMutex readerMutex
unsigned readerCount
PMutex starvationPreventer
PSemaphore writerSemaphore
PMutex writerMutex
unsigned writerCount
PDictionary< POrdinalKey,
Nest
nestedThreads
PMutex nestingMutex

Classes

class  Nest

Detailed Description

This class defines a thread synchonisation object.

This is a special type of mutual exclusion, where the excluded area may have multiple read threads but only one write thread and the read threads are blocked on write as well.


Constructor & Destructor Documentation

PReadWriteMutex::PReadWriteMutex (  ) 

PReadWriteMutex::PReadWriteMutex (  ) 


Member Function Documentation

void PReadWriteMutex::StartRead (  ) 

This function attempts to acquire the mutex for reading. This call may be nested and must have an equal number of EndRead() calls for the mutex to be released.

void PReadWriteMutex::EndRead (  ) 

This function attempts to release the mutex for reading.

void PReadWriteMutex::StartWrite (  ) 

This function attempts to acquire the mutex for writing. This call may be nested and must have an equal number of EndWrite() calls for the mutex to be released.

Note, if the same thread had a read lock previous to this call then the read lock is automatically released and reacquired when EndWrite() is called, unless an EndRead() is called. The EndRead() and EndWrite() calls do not have to be strictly nested.

It should also be noted that a consequence of this is that another thread may acquire the write lock before the thread that previously had the read lock. Thus it is impossibly to go straight from a read lock to write lock without the possiblility of the object being changed and application logic should take this into account.

void PReadWriteMutex::EndWrite (  ) 

This function attempts to release the mutex for writing. Note, if the same thread had a read lock when the StartWrite() was called which has not yet been released by an EndRead() call then this will reacquire the read lock.

It should also be noted that a consequence of this is that another thread may acquire the write lock before the thread that regains the read lock. Thus it is impossibly to go straight from a write lock to read lock without the possiblility of the object being changed and application logic should take this into account.

Nest* PReadWriteMutex::GetNest (  )  const [protected]

Nest& PReadWriteMutex::StartNest (  )  [protected]

void PReadWriteMutex::EndNest (  )  [protected]

void PReadWriteMutex::InternalStartRead (  )  [protected]

void PReadWriteMutex::InternalEndRead (  )  [protected]


Member Data Documentation

PSemaphore PReadWriteMutex::readerSemaphore [protected]

PMutex PReadWriteMutex::readerMutex [protected]

unsigned PReadWriteMutex::readerCount [protected]

PMutex PReadWriteMutex::starvationPreventer [protected]

PSemaphore PReadWriteMutex::writerSemaphore [protected]

PMutex PReadWriteMutex::writerMutex [protected]

unsigned PReadWriteMutex::writerCount [protected]

PDictionary<POrdinalKey, Nest> PReadWriteMutex::nestedThreads [protected]

PMutex PReadWriteMutex::nestingMutex [protected]


The documentation for this class was generated from the following file:
Generated on Fri Mar 7 06:25:06 2008 for PTLib by  doxygen 1.5.1