A mutex is used to protect a section of code such that at any time only a single thread can execute the code. More...
#include <SGThread.hxx>
Public Member Functions | |
SGMutex () | |
Create a new mutex. | |
~SGMutex () | |
Destroy a mutex object. | |
void | lock () |
Lock this mutex. | |
bool | trylock () |
Try to lock the mutex for the current thread. | |
void | unlock () |
Unlock this mutex. | |
Protected Attributes | |
pthread_mutex_t | mutex |
Pthread mutex. | |
Friends | |
class | SGPthreadCond |
A mutex is used to protect a section of code such that at any time only a single thread can execute the code.
Definition at line 162 of file SGThread.hxx.
SGMutex::SGMutex | ( | ) | [inline] |
Create a new mutex.
Under Linux this is a 'fast' mutex.
Definition at line 216 of file SGThread.hxx.
SGMutex::~SGMutex | ( | ) | [inline] |
Destroy a mutex object.
Note: it is the responsibility of the caller to ensure the mutex is unlocked before destruction occurs.
Definition at line 223 of file SGThread.hxx.
void SGMutex::lock | ( | void | ) | [inline] |
Lock this mutex.
If the mutex is currently unlocked, it becomes locked and owned by the calling thread. If the mutex is already locked by another thread, the calling thread is suspended until the mutex is unlocked. If the mutex is already locked and owned by the calling thread, the calling thread is suspended until the mutex is unlocked, effectively causing the calling thread to deadlock.
Definition at line 230 of file SGThread.hxx.
bool SGMutex::trylock | ( | ) |
Try to lock the mutex for the current thread.
Behaves like lock except that it doesn't block the calling thread.
Definition at line 49 of file SGThread.cxx.
void SGMutex::unlock | ( | ) | [inline] |
Unlock this mutex.
It is assumed that the mutex is locked and owned by the calling thread.
Definition at line 237 of file SGThread.hxx.