A mutex is mutual exclusion: a blocking lock. More...
#include <Mutex.h>
Inherits atscppapi::noncopyable.
Public Types | |
enum | Type { TYPE_NORMAL = 0, TYPE_RECURSIVE, TYPE_ERROR_CHECK } |
The available types of Mutexes. More... | |
Public Member Functions | |
Mutex (Type type=TYPE_NORMAL) | |
Create a mutex. | |
~Mutex () | |
bool | tryLock () |
Try to take the lock, this call will NOT block if the mutex cannot be taken. | |
void | lock () |
Block until the lock is taken, when this call returns the thread will be holding the lock. | |
void | unlock () |
Unlock the lock, this call is nonblocking. |
A mutex is mutual exclusion: a blocking lock.
The Mutex class uses pthreads for its implmentation.
Definition at line 44 of file Mutex.h.
The available types of Mutexes.
TYPE_NORMAL |
This type of Mutex will deadlock if locked by a thread already holding the lock. |
TYPE_RECURSIVE |
This type of Mutex will allow a thread holding the lock to lock it again; however, it must be unlocked the same number of times. |
TYPE_ERROR_CHECK |
This type of Mutex will return errno = EDEADLCK if a thread would deadlock by taking the lock after it already holds it. |
atscppapi::Mutex::Mutex | ( | Type | type = TYPE_NORMAL |
) | [inline] |
Create a mutex.
type | The Type of Mutex to create, the default is TYPE_NORMAL. |
Definition at line 62 of file Mutex.h.
References TYPE_ERROR_CHECK, TYPE_NORMAL, and TYPE_RECURSIVE.
void atscppapi::Mutex::lock | ( | ) | [inline] |
Block until the lock is taken, when this call returns the thread will be holding the lock.
Definition at line 97 of file Mutex.h.
Referenced by atscppapi::ScopedMutexLock::ScopedMutexLock().
bool atscppapi::Mutex::tryLock | ( | ) | [inline] |
Try to take the lock, this call will NOT block if the mutex cannot be taken.
Definition at line 90 of file Mutex.h.
Referenced by atscppapi::ScopedMutexTryLock::ScopedMutexTryLock().
void atscppapi::Mutex::unlock | ( | ) | [inline] |
Unlock the lock, this call is nonblocking.
Definition at line 104 of file Mutex.h.
Referenced by atscppapi::ScopedMutexLock::~ScopedMutexLock(), and atscppapi::ScopedMutexTryLock::~ScopedMutexTryLock().