Loki
0.1.7
|
#include <LevelMutex.h>
Public Member Functions | |
MutexLocker (volatile LevelMutexInfo &mutex, bool lock=true) | |
MutexLocker (volatile LevelMutexInfo &mutex, unsigned int milliSeconds, bool lock=true) | |
~MutexLocker (void) | |
Destructs the locker, and determines if it needs to unlock the mutex. | |
bool | Lock (void) |
bool | Unlock (void) |
bool | IsLocked (void) const |
Returns true if the mutex is locked by this object. | |
const volatile LevelMutexInfo & | GetMutex (void) const |
Provides access to mutex controlled by this. | |
You can place an instance of this as a local variable inside a function to lock a single mutex. It will lock the mutex if no error occurs, or throw if one does happen. When the function ends, the destructor will determine if it needs to unlock the mutex. This RAII technique insures the mutex gets unlocked even when exceptions occur.
|
explicit |
Creates an object to lock an unlock a mutex for a function. This will throw if an attempt to lock the mutex fails.
mutex | Reference to the mutex. |
lock | True if function wants to lock the mutex as this gets constructed. |
References Loki::LevelMutexInfo::GetLevel(), and Loki::LevelMutexInfo::Lock().
Loki::MutexLocker::MutexLocker | ( | volatile LevelMutexInfo & | mutex, |
unsigned int | milliSeconds, | ||
bool | lock = true |
||
) |
Creates an object to lock an unlock a mutex for a function. This waits a specified amount of time for another thread to unlock the mutex if it is locked. This will throw if an attempt to lock the mutex fails.
mutex | Reference to the mutex. |
milliSeconds | Amount of time to wait for another thread to unlock the mutex. |
lock | True if function wants to lock the mutex as this gets constructed. |
References Loki::LevelMutexInfo::GetLevel(), and Loki::LevelMutexInfo::Lock().
bool Loki::MutexLocker::Lock | ( | void | ) |
You can call this to lock (or relock) a mutex. In theory, you can lock and unlock a mutex several times within a function in order to give other threads access to a resource while this function does not need it.
References Loki::LevelMutexInfo::Lock().
bool Loki::MutexLocker::Unlock | ( | void | ) |
You can call this to unlock a mutex 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::Unlock().