#include <syncthrd.h>
Inheritance diagram for PReadWriteMutex:
Public Member Functions | |
Operations | |
void | StartRead () |
void | EndRead () |
void | StartWrite () |
void | EndWrite () |
Protected Member Functions | |
Nest * | GetNest () const |
Nest & | StartNest () |
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 |
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.
PReadWriteMutex::PReadWriteMutex | ( | ) |
PReadWriteMutex::PReadWriteMutex | ( | ) |
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] |
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] |