Loki
0.1.7
|
#include <LevelMutex.h>
Public Member Functions | |
MultiMutexLocker (LevelMutexInfo::MutexContainer &mutexes, bool lock=true) | |
MultiMutexLocker (LevelMutexInfo::MutexContainer &mutexes, unsigned int milliSeconds, bool lock=true) | |
~MultiMutexLocker (void) | |
Destructs the locker, and determines if it needs to unlock the mutexes. | |
bool | Lock (void) |
bool | Unlock (void) |
bool | IsLocked (void) const |
Returns true if the mutexes are locked by this object. | |
const LevelMutexInfo::MutexContainer & | GetMutexes (void) const |
Provides access to the collection of mutexes controlled by this. | |
You can place an instance of this as a local variable inside a function to lock a collection of mutexes. It locks them if no error occurs, or throws an exception if one does happen. When the function ends, the destructor determines if it needs to unlock the mutexes. This RAII technique insures the mutexes get unlocked even when exceptions occur. You will also have to construct a MutexContainer as a local object within the same function.
|
explicit |
Creates an object to lock and unlock a collection of mutexes for a function. This will throw if an attempt to lock any mutex fails. If an exception occurs, it unlocks mutexes it previously locked.
mutex | Reference to a collection of mutexes. |
lock | True if function wants to lock the mutex as this gets constructed. |
References Loki::LevelMutexInfo::MultiLock().
Loki::MultiMutexLocker::MultiMutexLocker | ( | LevelMutexInfo::MutexContainer & | mutexes, |
unsigned int | milliSeconds, | ||
bool | lock = true |
||
) |
Creates an object to lock and unlock a collection of mutexes for a function. This waits a specified amount of time for other threads to unlock each mutex that is locked. This will throw if an attempt to lock any mutex fails. If an exception occurs, it unlocks mutexes it previously locked.
mutexes | Reference to a collection of mutexes. |
milliSeconds | Amount of time to wait for another thread to unlock the mutex. |
lock | True if function wants to lock the mutexes as this gets constructed. |
References Loki::LevelMutexInfo::MultiLock().
bool Loki::MultiMutexLocker::Lock | ( | void | ) |
You can call this to lock (or relock) the mutexes. In theory, you can lock and unlock mutexes several times within a function in order to give other threads access to resources while this function does not need them.
References Loki::LevelMutexInfo::MultiLock().
bool Loki::MultiMutexLocker::Unlock | ( | void | ) |
You can call this to unlock the mutexes before the destructor does it. By unlocking the mutexes before returning, the function can do other operations without making other threads wait too long.
References Loki::LevelMutexInfo::MultiUnlock().