Main Page   Namespace List   Class Hierarchy   Compound List   Compound Members  

ZThread::RWLock Class Reference

#include <RWLock.h>

Inheritance diagram for ZThread::RWLock::

ZThread::BiasedRWLock ZThread::FairRWLock List of all members.

Public Methods

 RWLock () throw (Synchronization_Exception)
virtual ~RWLock () throw ()
LockablegetReadLock ()
LockablegetWriteLock ()

Protected Methods

virtual bool allowReader ()
virtual bool allowWriter ()
virtual void beforeRead () throw (Synchronization_Exception)
virtual void beforeWrite () throw (Synchronization_Exception)
virtual bool beforeRead (unsigned long) throw (Synchronization_Exception)
virtual bool beforeWrite (unsigned long) throw (Synchronization_Exception)
virtual void postRead () throw (Synchronization_Exception)
virtual void postWrite () throw (Synchronization_Exception)

Protected Attributes

FastMutex _mtxLock
 Serialize access to this object.

Condition _condRead
 Notified on read ready.

Condition _condWrite
 Notified on write read.

Lockable_readLock
 RLock.

Lockable_writeLock
 WLock.

int _fairnessCounter
 track fairness.

int _activeReaders
 track the current readers.

int _activeWriters
 track the current writers.

int _waitingReaders
 track the waiting readers.

int _waitingWriters
 track the waiting writers.


Detailed Description

Author:
Eric Crahen
Version:
1.3.0
Date:
03-10-2001

Read/Write lock provide a set of coordinated Lockable object that allow many Readers while there is no update in progress, but only 1 Writer & 0 Readers during an update

Because the general case where an RWLock would be used is one where you have more readers than writers, this lock will have a bias toward readers


Constructor & Destructor Documentation

RWLock ( ) throw (Synchronization_Exception)
 

Create a new RWLock

Exceptions:
Initialization_Exception   - thrown if resources could not be allocated

~RWLock ( ) throw () [virtual]
 

Destroy this RWLock


Member Function Documentation

bool allowReader ( ) [protected, virtual]
 

Checked before a lock is acquired. Changing this function in a subclass can create RWLocks with different biases.

Returns:
bool - true, allow lock to be acquired, false block

Reimplemented in ZThread::BiasedRWLock, and ZThread::FairRWLock.

bool allowWriter ( ) [protected, virtual]
 

Checked before a lock is acquired. Changing this function in a subclass can create RWLocks with different biases.

Returns:
bool - true, allow lock to be acquired, false block

bool beforeRead ( unsigned long ) throw (Synchronization_Exception) [protected, virtual]
 

Called just before a read lock tryAcquire()

Parameters:
long   - timeout the read will be called with
Parameters:
long  

void beforeRead ( ) throw (Synchronization_Exception) [protected, virtual]
 

Called just prior to a read lock acquire()

bool beforeWrite ( unsigned long ) throw (Synchronization_Exception) [protected, virtual]
 

Called just before a write lock tryAcquire()

Parameters:
long   - timeout the write will be called with
Parameters:
long  

void beforeWrite ( ) throw (Synchronization_Exception) [protected, virtual]
 

Called just prior to a write lock acquire()

Lockable * getReadLock ( ) [inline]
 

Get a reference to the read lock

Returns:
Lockable read lock

Lockable * getWriteLock ( ) [inline]
 

Get a reference to the write lock

Returns:
Lockable write lock

void postRead ( ) throw (Synchronization_Exception) [protected, virtual]
 

Called after a read lock is released

void postWrite ( ) throw (Synchronization_Exception) [protected, virtual]
 

Called after a write lock is released


The documentation for this class was generated from the following file:
Generated at Fri Aug 31 09:08:02 2001 for ZThread by doxygen1.2.8 written by Dimitri van Heesch, © 1997-2001