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

P::RWLock Class Reference
[Core library]

Read-write lock synchronization object. More...

#include <prwlock.h>

List of all members.

Public Member Functions

 RWLock (const char *name=0) throw (SyncError)
 Default constructor.

 ~RWLock () throw ()
 Destructor.

void readLock () throw (SyncError)
 Lock the read-write lock for reading.

bool tryReadLock (unsigned int timeout) throw (SyncError)
 Try to lock the read-write lock for reading with timeout.

void writeLock () throw (SyncError)
 Lock the read-write lock for writing.

bool tryWriteLock (unsigned int timeout) throw (SyncError)
 Try to lock the mutex for writing with timeout.

void unlock () throw (SyncError)
 Release the previously acquired lock.


Detailed Description

Read-write lock synchronization object.

A read-write lock is like a mutex but allows multiple readers or one writer to hold the lock at the same time. Also, read-write locks are not recursive. On Win32 systems the read-write lock is implemented using a mutex which does not allow multiple readers.

See also:
Mutex
Author:
Christian Prochnow <cproch@seculogix.de>

Definition at line 38 of file prwlock.h.


Constructor & Destructor Documentation

P::RWLock::RWLock const char *  name = 0  )  throw (SyncError)
 

Default constructor.

Construct the RWLock object. If a name is given, the read-write lock can be shared by multiple processes, otherwise a process- local rwlock is created. On POSIX systems that support SYSV shared memory process-shared rwlock's are implemented using a shared memory segment which contains the pthread_rwlock_t structure.

Parameters:
name a pointer to the name of the rwlock which is used to identify it, or a NULL pointer if the mutex should be process-local. On POSIX systems the name must reffer to an existing file and the process must be able to stat() the file.
Exceptions:
SyncError 

P::RWLock::~RWLock  )  throw ()
 

Destructor.

The destructor destroys the read-write lock. The rwlock must be in unlocked state when the destructor is called. On POSIX systems this also removes the shared memory segment which contains the pthread_rwlock_t structure if no more processes reference to it.


Member Function Documentation

void P::RWLock::readLock  )  throw (SyncError)
 

Lock the read-write lock for reading.

If the read-write lock is currently locked for writing by another thread the calling thread suspends until the write-lock has been released. If another thread already holds a read-lock, or the read- write lock is currently unlocked the function returns immediatly.

Exceptions:
SyncError 

Referenced by P::RWLock::ReadLock::operator=().

bool P::RWLock::tryReadLock unsigned int  timeout  )  throw (SyncError)
 

Try to lock the read-write lock for reading with timeout.

This method does the same than readLock() but also supports a timeout- value. If the read-lock cannot be acquired in the given interval the method returns without locking the rwlock and a FALSE return value.

Parameters:
timeout the timeout in milliseconds to wait for the read-lock. If zero is specified the method returns immediatly.
Returns:
TRUE if the read-lock has been acquired, FALSE otherwise.
Exceptions:
SyncError 

bool P::RWLock::tryWriteLock unsigned int  timeout  )  throw (SyncError)
 

Try to lock the mutex for writing with timeout.

This method does the same than writeLock() but also supports a timeout- value. If the lock cannot be acquired in the given interval the method returns without locking the rwlock and a FALSE return value.

Parameters:
timeout the timeout in milliseconds to wait for the read-lock. If zero is specified the method returns immediatly.
Returns:
TRUE if the write-lock has been acquired, FALSE otherwise.
Exceptions:
SyncError 

void P::RWLock::unlock  )  throw (SyncError)
 

Release the previously acquired lock.

void P::RWLock::writeLock  )  throw (SyncError)
 

Lock the read-write lock for writing.

If the read-write lock is currently locked for reading or writing by another thread, the calling thread suspends until the lock has been released. If the read-write lock is currently unlocked, the function returns immediatly.

Exceptions:
SyncError 

Referenced by P::RWLock::WriteLock::operator=().


The documentation for this class was generated from the following file:
Generated on Fri Mar 12 21:08:35 2004 for P::Classes by doxygen 1.3.3