Loki
0.1.7
|
#include <LevelMutex.h>
Public Member Functions | |
LevelMutex (unsigned int level=DefaultLevel) | |
~LevelMutex (void) | |
The destructor. | |
const volatile MutexPolicy & | GetMutexPolicy (void) const volatile |
virtual MutexErrors::Type | TryLock (void) volatile |
virtual MutexErrors::Type | Lock (void) volatile |
virtual MutexErrors::Type | Lock (unsigned int milliSeconds) volatile |
virtual MutexErrors::Type | Unlock (void) volatile |
![]() | |
unsigned int | GetLevel (void) const volatile |
Returns the level of this mutex. | |
bool | IsLocked (void) const volatile |
Returns true if this mutex was locked at least once. | |
unsigned int | GetLockCount (void) const volatile |
Returns count of how many times this mutex got locked. | |
const volatile LevelMutexInfo * | GetPrevious (void) const volatile |
Returns pointer to mutex previously locked by the thread which locked this. | |
bool | IsRecentLock (void) const volatile |
bool | IsRecentLock (unsigned int count) const volatile |
bool | IsLockedByCurrentThread (void) const volatile |
Returns true if this was locked by current thread. | |
bool | IsLockedByAnotherThread (void) const volatile |
Returns true if this was locked by another thread. | |
Additional Inherited Members | |
![]() | |
typedef ::std::vector < volatile LevelMutexInfo * > | MutexContainer |
Container for locking multiple mutexes at once. | |
![]() | |
static MutexErrors::Type | MultiLock (MutexContainer &mutexes) |
static MutexErrors::Type | MultiLock (MutexContainer &mutexes, unsigned int milliSeconds) |
static MutexErrors::Type | MultiUnlock (MutexContainer &mutexes) |
static const volatile LevelMutexInfo * | GetCurrentMutex (void) |
![]() | |
static const unsigned int | UnlockedLevel = 0xFFFFFFFF |
![]() | |
LevelMutexInfo (unsigned int level) | |
virtual | ~LevelMutexInfo (void) |
The destructor only gets called by the derived class. | |
void | PostLock (void) volatile |
void | PreUnlock (void) volatile |
Gets called just before an attempt to unlock a mutex. | |
void | IncrementCount (void) volatile |
Called to relock a mutex already locked by the current thread. | |
void | DecrementCount (void) volatile |
Called to unlock a mutex locked multiple times by the current thread. | |
bool | IsValid (void) const volatile |
![]() | |
static bool | IsValidList (void) |
Levelized mutex class prevents deadlocks by requiring programs to lock mutexes in the same order, and unlock them in reverse order. This is accomplished by forcing each mutex to have a level and forcing code to lock mutexes with higher levels before locking mutexes at lower levels. If you want to lock several mutexes, they must be locked in decreasing order by level, or if they are all of the same level, then locked by LevelMutex::MultiLock.
|
inlineexplicit |
This constructor allows callers to replace the default level with another value. It also acts as the default constructor for existing code which uses default construction for mutexes. This is the only time the DefaultLevel template parameter gets used.
References Loki::LevelMutexInfo::IsValid().
|
inline |
These functions allow callers to access the mutex in case they need to modify specific values in the MutexPolicy (e.g. - sleep time, functors to call as tasks, etc...) There is one function for every combination of const and volatile qualifiers so callers get a reference to a MutexPolicy with the proper qualifiers.
|
inlinevirtual |
Blocking call will attempt to lock mutex and wait until it can lock. This may throw an exception if the lock failed or an error occurred - if that is what the error policy specifies.
Implements Loki::LevelMutexInfo.
References Loki::LevelMutexInfo::GetLevel(), Loki::LevelMutexInfo::IsLockedByCurrentThread(), Loki::LevelMutexInfo::IsValid(), and Loki::LevelMutexInfo::PostLock().
|
inlinevirtual |
Attempts to lock mutex, but only waits for a limited amount of time before it gives up. Will return quickly if an error occurs before any attempt to lock. This may throw an exception if the lock failed or an error occurred - if that is what the error policy specifies.
milliSeconds | How long to wait. |
Implements Loki::LevelMutexInfo.
References Loki::LevelMutexInfo::GetLevel(), Loki::LevelMutexInfo::IsLockedByCurrentThread(), Loki::LevelMutexInfo::IsValid(), and Loki::LevelMutexInfo::PostLock().
|
inlinevirtual |
Tries to lock mutex, and returns immediately if mutex already locked by another thread. It will return immediately with a value of AlreadyLocked if the mutex was locked by a different thread. It may throw an exception or assert when errors occur if the ErrorPolicy class implements that behavior.
Implements Loki::LevelMutexInfo.
References Loki::LevelMutexInfo::GetLevel(), Loki::LevelMutexInfo::GetLockCount(), Loki::LevelMutexInfo::IsValid(), and Loki::LevelMutexInfo::PostLock().
|
inlinevirtual |
Unlocks the mutex, or returns an error condition. This may throw an exception if the lock failed or an error occurred - if that is what the error policy specifies.
Implements Loki::LevelMutexInfo.
References Loki::LevelMutexInfo::GetLevel(), Loki::LevelMutexInfo::IsValid(), Loki::LevelMutexInfo::PostLock(), and Loki::LevelMutexInfo::PreUnlock().