KJB
|
simple RAII class to grab and release a mutex More...
#include <l_mt_mutexlock.h>
Public Member Functions | |
Mutex_lock (kjb_c::kjb_pthread_mutex_t *m) | |
establish a lock on the mutex (as a C-style struct) More... | |
Mutex_lock (Pthread_mutex &m) | |
establish a lock on the mutex object (as a reference) More... | |
Mutex_lock (Pthread_mutex *m) | |
establish a lock on the mutex object pointer More... | |
void | release () |
release the mutex for others (safe to call twice) More... | |
~Mutex_lock () | |
dtor releases the mutex More... | |
simple RAII class to grab and release a mutex
All this does is lock a mutex at creation time, and guarantee that it gets unlocked, unless an abort occurs. The ctor accepts either a pointer to a kjb_c::kjb_pthread_t object (the C-language style struct used by the multithread wrapper), or a C++ object, either a Pthread_mutex reference or pointer (it does not matter which).
If you wish to unlock the mutex prior to the destruction of this object, just call the release() method. It is safe to call release() multiple times on the same object – only the first one has effect, the rest are benign NOPs. However, if for some reason the mutex cannot be unlocked, the object's destructor will abort the program.
|
inline |
establish a lock on the mutex (as a C-style struct)
|
inline |
establish a lock on the mutex object (as a reference)
|
inline |
establish a lock on the mutex object pointer
|
inline |
dtor releases the mutex
|
inline |
release the mutex for others (safe to call twice)