Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

MCRWLock Class Reference

Scoped lock object for Readers/Writer mutex object. More...

#include <mcllib/MCRWLock.h>

Inheritance diagram for MCRWLock:

MCNonCopy List of all members.

Public Member Functions

bool isLocked () const
 Test to see if the mutex is locked.
void lock (bool reader)
 Lock the mutex.
void lock ()
 Read-lock the mutex.
 MCRWLock (MCRWMutex *pMutex, bool reader, bool locked)
 Construct a lock, optionally locking the provided mutex.
 MCRWLock (MCRWMutex *pMutex, bool reader)
 Construct a lock, locking the provided mutex.
 MCRWLock (MCRWMutex *pMutex)
 Construct a lock, read-locking the provided mutex.
void unlock ()
 Unlock the mutex.
 ~MCRWLock ()
 Unlock the mutex provided at construction if it is locked.

Detailed Description

Scoped lock object for Readers/Writer mutex object.

Provides automatic locking and unlocking based on scope. Lock objects lock a readers/writer mutex (provided at construction time) and unlock the mutex at destruction. Methods are provided for locking and unlocking the mutex other than at construction/destruction. However the easiest way to use this object is in the automatic mode. This kind of scoped locking frees the developer from the need to worry about remembering to do an unlock for each lock.

See also:
MCRWMutex


Constructor & Destructor Documentation

MCRWLock MCRWMutex pMutex  ) 
 

Construct a lock, read-locking the provided mutex.

Parameters:
pMutex an RWMutex object which cannot be a NULL pointer. pMutex is typically the address of a member variable of an object.

MCRWLock MCRWMutex pMutex,
bool  reader
 

Construct a lock, locking the provided mutex.

Parameters:
pMutex an RWMutex object which cannot be a NULL pointer. pMutex is typically the address of a member variable of an object.
reader if true the mutex is read locked otherwise it is write locked.

MCRWLock MCRWMutex pMutex,
bool  reader,
bool  locked
 

Construct a lock, optionally locking the provided mutex.

Parameters:
pMutex an RWMutex object which cannot be a NULL pointer. pMutex is typically the address of a member variable of an object.
reader if true the mutex is read locked otherwise it is write locked.
locked if true the mutex is locked, otherwise the reader parameter is ignored and the mutex is not locked.

~MCRWLock  ) 
 

Unlock the mutex provided at construction if it is locked.

This provides for scoped locking. When the lock object goes out of scope, the mutex is unlocked if it was locked. This prevents mutexes being held onto inadvertently


Member Function Documentation

bool isLocked  )  const
 

Test to see if the mutex is locked.

Returns:
true if the mutex is locked.

void lock bool  reader  ) 
 

Lock the mutex.

If the mutex is already locked a fatal exception is thrown. This is indicative of an application programming error. lock() waits indefinitely until the mutex becomes available.

Parameters:
reader if true the mutex is read locked otherwise it is write locked.

void lock  ) 
 

Read-lock the mutex.

If the mutex is already locked a fatal exception is thrown. This is indicative of an application programming error. lock() waits indefinitely until the mutex becomes available.

void unlock  ) 
 

Unlock the mutex.

If the mutex is already unlocked a fatal exception is thrown. This is indicative of an application programming error. One or more waiting threads will be eligible to lock the mutex depending one the kind of lock they are attempting.


Generated on Wed Jan 12 19:05:50 2005 for MCLLIB by  doxygen 1.3.9.1