#include <wefts_rrwmutex.h>
Inheritance diagram for Wefts::RRWMutex:
Public Methods | |
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 | promote (bool fence) throw ( InvalidError ) |
Promote the lock from read only to readwrite. | |
virtual bool | promote (double time=0.0, bool fence=false) throw ( InvalidError ) |
Promotes a mutex to Write Lock. | |
virtual bool | lockWrite (bool fence) |
Locks the mutex for writing. | |
virtual bool | lockWrite (double time=0.0, bool fence=false) |
Locks the mutex for writing. | |
virtual void | unlock () throw ( InvalidError ) |
Unlocks the mutex. | |
virtual void | handleCleanup (int code) |
Callback method called on cleanup. | |
Private Attributes | |
int | m_fence |
OSThread | m_owner |
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 onwership as soon as the last reader that had control over it finishes its operations.
This mutex class ereditates 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 cancelled by another thread using deferred cancelation schemes; RRWMutex()lock() are cancelation points, and care must be taken to 1) arrive at this point ready to be cancelled or 2) disable cancelation.
|
Initializes the internal members of the mutex.
|
|
Callback method called on cleanup. When a thread is terminated (stopped or finished), and a cleanup request have been set, this method is called. Use the code parameter to decide what action among the possible ones must be taken. 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 untill all the read lockers have relased 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 achived 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 cancelation point, so actions must be taken to prevent cancelation, or to becanceled cleanly.
Reimplemented from Wefts::RWMutex. |
|
Locks the mutex for writing. As the RWMutex::lockWrite(), but with the add of the fence.
|
|
Locks the mutex for writing. 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.
|
|
Promotes a mutex to Write Lock. As the RWMutex::promote(), but with the add of the fence.
|
|
Promote the lock from read only to readwrite. This methods works like the one 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. |
|
|
|
|