![]() |
L4Re Operating System Framework
Interface and Usage Documentation
|
Basic lock guard implementation that prevents forgotten unlocks on exit paths from a method or a block of code. More...
#include <lock_guard.h>
Public Member Functions | |
Lock_guard (pthread_mutex_t &lock) | |
Construct the lock guard and lock the associated mutex. | |
Lock_guard (Lock_guard &&guard) | |
Move constructor from other lock guard. | |
Lock_guard & | operator= (Lock_guard &&guard) |
Move assignment from other lock guard. | |
int | status () const |
Return last lock/unlock operation error status. | |
~Lock_guard () | |
Lock guard destructor. | |
Basic lock guard implementation that prevents forgotten unlocks on exit paths from a method or a block of code.
Targeting pthread_mutex_t
.
An instance of lock guard cannot be copied, but it can be moved.
The typical usage pattern of the lock guard is:
Definition at line 44 of file lock_guard.h.
|
inlineexplicit |
Construct the lock guard and lock the associated mutex.
The error condition of the locking operation can be checked by the status() method.
lock | Associated mutex to be locked. |
Definition at line 59 of file lock_guard.h.
|
inline |
Move constructor from other lock guard.
The mutex associated with the other lock guard is kept locked.
guard | Lock guard to be moved. |
Definition at line 71 of file lock_guard.h.
|
inline |
Lock guard destructor.
The associated mutex (if any) is unlocked.
There is no mechanism for indicating any error conditions. However, if the mutex has been previously locked successfully by this class and if the implementation of the mutex behaves according to the POSIX specification, the construction of this class guarantees that the unlock operation does not fail.
Definition at line 126 of file lock_guard.h.
|
inline |
Move assignment from other lock guard.
The mutex currently associated with this lock guard is unlocked. The mutex associated with the other lock guard is kept locked.
There is no mechanism for indicating any error conditions of the unlocking operation. However, if the mutex has been previously locked successfully by this class and if the implementation of the mutex behaves according to the POSIX specification, the construction of this class guarantees that the unlock operation does not fail.
guard | Lock guard to be moved. |
Definition at line 90 of file lock_guard.h.
|
inline |
Return last lock/unlock operation error status.
Definition at line 110 of file lock_guard.h.