Embedded Multicore Building Blocks V1.0.0
|
Flexible ownership wrapper for a mutex. More...
#include <mutex.h>
Public Member Functions | |
UniqueLock () | |
Creates a lock without assigned mutex. More... | |
UniqueLock (Mutex &mutex) | |
Creates a lock from an unlocked mutex and locks it. More... | |
UniqueLock (Mutex &mutex, DeferLockTag) | |
Creates a lock from an unlocked mutex without locking it. More... | |
UniqueLock (Mutex &mutex, TryLockTag) | |
Creates a lock from an unlocked mutex and tries to lock it. More... | |
UniqueLock (Mutex &mutex, AdoptLockTag) | |
Creates a lock from an already locked mutex. More... | |
~UniqueLock () | |
Unlocks the mutex if owned. More... | |
void | Lock () |
Waits until the mutex is unlocked and locks it. More... | |
bool | TryLock () |
Tries to lock the mutex and returns immediately. More... | |
void | Unlock () |
Unlocks the mutex. More... | |
void | Swap (UniqueLock< Mutex > &other) |
Exchanges ownership of the wrapped mutex with another lock. More... | |
Mutex * | Release () |
Gives up ownership of the mutex and returns a pointer to it. More... | |
bool | OwnsLock () const |
Checks whether the mutex is owned and locked. More... | |
Flexible ownership wrapper for a mutex.
Provides exception controlled locking of a mutex with non-recursive semantics, that gives more flexibility than LockGuard but also has slightly increased memory and processing overhead. Each instance of a UniqueLock can be used by one thread only!
Mutex | Used mutex type. Has to fulfil the Mutex Concept. |
embb::base::UniqueLock< Mutex >::UniqueLock | ( | ) |
Creates a lock without assigned mutex.
A mutex can be assigned to the lock using the method Swap().
|
explicit |
Creates a lock from an unlocked mutex and locks it.
mutex
is unlocked [in] | mutex | Mutex to be managed. |
embb::base::UniqueLock< Mutex >::UniqueLock | ( | Mutex & | mutex, |
DeferLockTag | |||
) |
Creates a lock from an unlocked mutex without locking it.
mutex
is unlocked [in] | mutex | Mutex to be managed |
embb::base::UniqueLock< Mutex >::UniqueLock | ( | Mutex & | mutex, |
TryLockTag | |||
) |
Creates a lock from an unlocked mutex and tries to lock it.
mutex
is unlocked [in] | mutex | Mutex to be managed |
embb::base::UniqueLock< Mutex >::UniqueLock | ( | Mutex & | mutex, |
AdoptLockTag | |||
) |
Creates a lock from an already locked mutex.
mutex
is locked [in] | mutex | Mutex to be managed |
embb::base::UniqueLock< Mutex >::~UniqueLock | ( | ) |
Unlocks the mutex if owned.
void embb::base::UniqueLock< Mutex >::Lock | ( | ) |
Waits until the mutex is unlocked and locks it.
ErrorException,if | no mutex is set or it is locked |
bool embb::base::UniqueLock< Mutex >::TryLock | ( | ) |
Tries to lock the mutex and returns immediately.
true
if the mutex could be locked, otherwise false
. ErrorException,if | no mutex is set |
void embb::base::UniqueLock< Mutex >::Unlock | ( | ) |
Unlocks the mutex.
ErrorException,if | no mutex is set or it is not locked |
void embb::base::UniqueLock< Mutex >::Swap | ( | UniqueLock< Mutex > & | other | ) |
Exchanges ownership of the wrapped mutex with another lock.
[in,out] | other | The lock to exchange ownership with |
Mutex* embb::base::UniqueLock< Mutex >::Release | ( | ) |
Gives up ownership of the mutex and returns a pointer to it.
bool embb::base::UniqueLock< Mutex >::OwnsLock | ( | ) | const |
Checks whether the mutex is owned and locked.
true
if mutex is locked, otherwise false
.