#include <wefts_rrwmutex.h>
Inheritance diagram for Wefts::RRWMutex:
Read locks can be achieved as long as only read locks have been achieved; write locks can be achieved only by one thread at a time, and only if no read locks are currently held.
In this mutex kind, write locks are reentrant. Also, a write locker can require to rise a read lock fence, thus blocking any further request of new read lockers. This means that no new read lock will be allowed on the mutex, and the write locker will take ownership as soon as the last reader that had control over it finishes its operations.
This mutex class inherit the read lock promotion ability of its ancestor. It is also possible to promote a read-lock to write-lock while rising the read lock fence.
Also, this mutex lock() requests can be canceled by another thread using deferred cancellation schemes; RRWMutex()::lock() are cancellation points, and care must be taken to 1) arrive at this point ready to be canceled or 2) disable cancellation.
Public Member Functions | |
RRWMutex () | |
Initializes the internal members of the mutex. | |
virtual bool | lockRead (double seconds=0.0) |
Try to lock for reading this mutex for a certain time, or forever. | |
virtual bool | tryLockRead () |
Try to lock a mutex for reading and returns immediately. | |
virtual bool | promoteFence (double time=0.0, bool fence=true) throw ( InvalidError ) |
Promotes a mutex to Write Lock. | |
virtual bool | promote (double time=0.0) throw ( InvalidError ) |
Promotes a mutex to Write Lock, rising the fence Calls promoteFence( 0.0, true ), that is waits forever to acquire a write lock and rises the fence preventing readers from locking again. | |
virtual bool | lockWriteFence (double time=0.0, bool fence=true) |
Locks the mutex for writing, possibly rising the fence. | |
virtual bool | lockWrite (double seconds=0.0) |
Locks the mutex for writing, without rising the fence. | |
void | degrade () throw ( InvalidError ) |
Degrade the mutex from read-write to read only. | |
virtual void | unlock () throw ( InvalidError ) |
Unlocks the mutex. | |
virtual void | handleCleanup (int code, void *caller=0) |
Private Attributes | |
int | m_fence |
OSThread | m_owner |
|
Initializes the internal members of the mutex.
|
|
Degrade the mutex from read-write to read only. Releases the write lock held by the calling thread, but maintain grip as a reader, without giving away the lock. This will prevent writers from locking the mutex in the meanwhile, so a degraded mutex will still grant that the locked data are not changed, while this cannot be granted if the mutex is unlocked and then reacquired read-only. This function does checks if the calling thread is the rightful owner of the mutex, and issues an exception if it isn't. Being reentrant, this function must be called a number of time equal to the write locks acquired on the mutex to drop the write-only rights. Also, unlock() calls have the same effect as degrade() until the last lock is being held; is the last call (degrade or unlock) to determine if the mutex is retained read-only or not.
Reimplemented from Wefts::RWMutex. |
|
Reimplemented from Wefts::RWMutex. |
|
Try to lock for reading this mutex for a certain time, or forever. Any amount of read locks can be achieved by the calling thread or by other read-locking threads. After that a read lock has been achieved, write lock requests will be blocked until all the read lockers have released their locks. If a write locker has risen the read fence, this function will block the calling thread also if the writer is WAITING to achieve the lock. If the time parameter is given, and if the lock can be achieved during the given time, the method returns true, else the method return false. If the parameter is 0, this method returns always true. This method is a cancellation point, so actions must be taken to prevent cancellation, or to be canceled cleanly.
Reimplemented from Wefts::RWMutex. |
|
Locks the mutex for writing, without rising the fence. Calls lockWrite( seconds, false ).
Reimplemented from Wefts::RWMutex. |
|
Locks the mutex for writing, possibly rising the fence. After this call has returned any request of lock (both read or write) will cause blocking of the caller until the owner of this thread releases the lock. This method is not reentrant, so never call lockWrite() twice from the same thread. Works as the RWMutex::lockWrite(), but with the ability to rise the reader's fence.
|
|
Promotes a mutex to Write Lock, rising the fence Calls promoteFence( 0.0, true ), that is waits forever to acquire a write lock and rises the fence preventing readers from locking again.
Reimplemented from Wefts::RWMutex. |
|
Promotes a mutex to Write Lock. This methods works like the RWMutex::promote() provided in its ancestor, but it has also the ability to rise the fence, to prevent further readers to gain control of the mutex while this thread is waiting to be promoted.
|
|
Try to lock a mutex for reading and returns immediately.
Reimplemented from Wefts::RWMutex. |
|
Unlocks the mutex. Releases the lock held by the calling thread (be it a read-only lock or a write lock). If the mutex is locked for writing and the calling thread is not the owner of the lock, this call is ignored.
Reimplemented from Wefts::RWMutex. |
|
|
|
|