#include <wefts_xmutex.h>
Inheritance diagram for Wefts::XMutex:
Public Methods | |
XMutex () | |
Initializes the mutex. | |
void | lock () |
Lock the mutex. | |
bool | lock (double seconds) |
Try to lock a mutex for a given amount of seconds. | |
bool | tryLock () |
Try to lock a mutex and returns immediately. | |
void | unlock () |
Unlock a mutex. | |
bool | own () |
Returns true if current thread owns the mutex. | |
bool | locked () |
Returns true if the mutex has been locked. | |
void | handleCleanup (int) |
Cleanup routines. | |
Private Attributes | |
Condition | m_cond |
Mutex | m_mutex |
int | m_locked |
int | m_waiting |
OSThread | m_owner |
This class implements a mutex with advanced behavior, that can also be used as a base to build even more complex syncrhonization objects. Among the capabilities of this class are:
XMutex takes care that on lock method exit the mutex is either locked or unlocked, and that cancelation may happen only when mutex is unlocked. As there aren't undefined outcomes, the mutex can be considered cancelation safe.
Anyhow, XMutex has a major drawback in efficiency; lock and unlock requests are relatively slow, so it must be used to synchronize time-sparse operations, or operations having an heavy set of instructions to be mutexed, so that the ovherhead of this class is transcurable.
|
Initializes the mutex.
|
|
Cleanup routines.
Implements Wefts::CleanupHandler. |
|
Try to lock a mutex for a given amount of seconds. If the timeout expires and the lock can't be achived, the thread is resumed and the function returns false. |
|
Lock the mutex. The calling thread is suspended until the lock is achived; another thread may stop this one cleanly, preventing it from gainig the lock. The lock owner can also lock the mutex more than one time, allowing this method to be used in recursive calls. The unlock() method must be called the same amount of times lock() has been called to release the mutex. |
|
Returns true if the mutex has been locked. This data may change even before the reading thread has a chance to test its value, so it must not be relied on; it is provided for debugging reasons. |
|
Returns true if current thread owns the mutex.
|
|
Try to lock a mutex and returns immediately. On success, retruns true |
|
Unlock a mutex. Requests to unlock a mutex from a thread that is not owning the lock are ignored. |
|
|
|
|
|
|
|
|
|
|