ShlubluLib
v0.5
ShlubluLib is a lightweight, modular, general purpose, open-source C++ library for Linux and Windows.
|
Recursive mutex. More...
#include <MutexLock.h>
Classes | |
class | LockingError |
MutexLock throws this exception when a locking or unlocking operation is not legal. More... | |
Public Types | |
using | Guard = std::lock_guard< MutexLock > |
RAII convenience wrapper. More... | |
Public Member Functions | |
MutexLock (MutexLock const &)=delete | |
Copy constructor is deleted. | |
MutexLock (MutexLock &&)=delete | |
Move constructor is deleted. | |
MutexLock (bool locked=false) | |
Constructor. More... | |
virtual | ~MutexLock () noexcept |
Destructor. More... | |
void | lock () |
Locks the mutex once available. More... | |
void | unlock () |
Unlocks the mutex. More... | |
unsigned | lockLevel () const |
Returns the lock level of the mutex. More... | |
bool | currentThreadIsOwner () const |
Tells whether the current thread owns the mutex. More... | |
Recursive mutex.
Underlying implementation is based on std::recursive_mutex
Typical examples of use
using shlublu::MutexLock::Guard = std::lock_guard<MutexLock> |
RAII convenience wrapper.
This wrapper guarantees that the mutex will be unlock at the moment its destructor will be called. Used in a function or method, this makes MutexLock::unlock()
to be called at return
or throw
time with no further manual handling.
Based on the standard std::lock_guard
implementation.
Example
shlublu::MutexLock::MutexLock | ( | bool | locked = false | ) |
Constructor.
locked | Initial state of the mutex. |
|
virtualnoexcept |
void shlublu::MutexLock::lock | ( | ) |
Locks the mutex once available.
Queues until the mutex is available for locking. A lock is available if:
void shlublu::MutexLock::unlock | ( | ) |
Unlocks the mutex.
LockingError | if the mutex is not locked or if it is locked by another thread |
unsigned shlublu::MutexLock::lockLevel | ( | ) | const |
Returns the lock level of the mutex.
bool shlublu::MutexLock::currentThreadIsOwner | ( | ) | const |
Tells whether the current thread owns the mutex.
true
if the calling thread is the owner, false
otherwise.