# Loki::SleepLevelMutex Class Reference

`#include <LevelMutex.h>`

Inheritance diagram for Loki::SleepLevelMutex:
[legend]
Collaboration diagram for Loki::SleepLevelMutex:
[legend]

List of all members.

## Public Member Functions

| SleepLevelMutex (unsigned int level)
virtual | ~SleepLevelMutex (void)
| Destructs the mutex.
virtual MutexErrors::Type | Lock (void) volatile

## Detailed Description

Implements a sleeping loop to wait for the mutex to unlock.

Purpose
  Since this class puts the thread to sleep for short intervals, you can use this class for most of your mutexes. Especially for locking any high level resources where any one operation on the resouce consumes many CPU cycles. The purpose of this mutex is to reduce the number of CPU cycles spent in idle loops. All SleepLevelMutex's should have higher levels than all your SpinLevelMutex's.

Dependence on SpinLevelMutex
  This utilizes SpinLevelMutex so it does not have to re-implement the DoTryLock and DoUnlock functions the same way. All it really needs is a DoLock function and the amount of time it should sleep if an attempt to lock a function fails.

## Constructor & Destructor Documentation

Loki::SleepLevelMutex::SleepLevelMutex | ( | unsigned int | level | ) | `[explicit]`

Constructs a levelized mutex that puts threads to sleep while they wait for another thread to unlock the mutex.

Parameters:

  | level | Level of this mutex.

## Member Function Documentation

MutexErrors::Type Loki::SleepLevelMutex::Lock | ( | void |  | ) | volatile`[virtual]`

Attempts to lock a mutex, and if it fails, then sleeps for a while before attempting again.

Reimplemented from Loki::SpinLevelMutex.

The documentation for this class was generated from the following files:

- LevelMutex.h
- LevelMutex.cpp