# PReadWriteMutex Class Reference

This class defines a thread synchronisation object. More...

`#include <syncthrd.h>`

Inheritance diagram for PReadWriteMutex:

List of all members.

## Public Member Functions

Construction
| PReadWriteMutex ()
| ~PReadWriteMutex ()
Operations
void | StartRead ()
| This function attempts to acquire the mutex for reading.
void | EndRead ()
| This function attempts to release the mutex for reading.
void | StartWrite ()
| This function attempts to acquire the mutex for writing.
void | EndWrite ()
| This function attempts to release the mutex for writing.

## Protected Types

typedef std::map< PThreadIdentifier, Nest > | NestMap

## Protected Member Functions

Nest * | GetNest ()
Nest & | StartNest ()
void | EndNest ()
void | InternalStartRead ()
void | InternalEndRead ()
void | InternalWait (PSemaphore &semaphore) const

## Protected Attributes

PSemaphore | readerSemaphore
PMutex | readerMutex
unsigned | readerCount
PMutex | starvationPreventer
PSemaphore | writerSemaphore
PMutex | writerMutex
unsigned | writerCount
NestMap | m_nestedThreads
PMutex | m_nestingMutex

## Classes

class | Nest

## Detailed Description

This class defines a thread synchronisation 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.

## Member Typedef Documentation

typedef std::map<PThreadIdentifier, Nest> PReadWriteMutex::NestMap `[protected]`

## Constructor & Destructor Documentation

PReadWriteMutex::PReadWriteMutex | ( |  | ) |

PReadWriteMutex::~PReadWriteMutex | ( |  | ) |

## Member Function Documentation

void PReadWriteMutex::EndNest | ( |  | ) | `[protected]`

void PReadWriteMutex::EndRead | ( |  | ) |

This function attempts to release the mutex for reading.

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 | ( |  | ) | `[protected]`

void PReadWriteMutex::InternalEndRead | ( |  | ) | `[protected]`

void PReadWriteMutex::InternalStartRead | ( |  | ) | `[protected]`

void PReadWriteMutex::InternalWait | ( | PSemaphore & | semaphore | ) | const`[protected]`

Nest& PReadWriteMutex::StartNest | ( |  | ) | `[protected]`

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::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.

## Member Data Documentation

NestMap PReadWriteMutex::m_nestedThreads `[protected]`

PMutex PReadWriteMutex::m_nestingMutex `[protected]`

unsigned PReadWriteMutex::readerCount `[protected]`

PMutex PReadWriteMutex::readerMutex `[protected]`

PSemaphore PReadWriteMutex::readerSemaphore `[protected]`

PMutex PReadWriteMutex::starvationPreventer `[protected]`

unsigned PReadWriteMutex::writerCount `[protected]`

PMutex PReadWriteMutex::writerMutex `[protected]`

PSemaphore PReadWriteMutex::writerSemaphore `[protected]`

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

- syncthrd.h