|
Open Model Railroad Network (OpenMRN)
|
Helper class that simulates a (non-reentrant) mutex using the Allocator queue and a single QueueMember token. More...
#include <AsyncMutex.hxx>
Classes | |
| class | Token |
| Synchronously locks the mutex. More... | |
Public Member Functions | |
| AsyncMutex () | |
| Creates an allocator mutex. | |
| void | CheckToken (QMember *token) |
| Crashes if the the particular value is not the token associated with this mutex. | |
| void | AssertLocked () |
| Crashes if the mutex is not locked. | |
| void | AssertUnlocked () |
| Crashes if the mutex is locked. | |
| void | Unlock () |
| Unlocks the mutex. Crashes if the mutex is unlocked. | |
Public Member Functions inherited from QAsync | |
| QAsync () | |
| Default Constructor. | |
| ~QAsync () | |
| Default destructor. | |
| void | insert (QMember *item, unsigned index=0) |
| Add an item to the back of the queue. | |
| void | next_async (Executable *flow) |
| Get an item from the front of the queue. | |
| QMember * | next (unsigned index) |
| Get an item from the front of the queue. | |
| Result | next () |
| Get an item from the front of the queue. | |
| Result | next_locked () |
| Get an item from the front of the queue. | |
| size_t | pending (unsigned index) |
| Get the number of pending items in the queue. | |
| size_t | pending () |
| Get the number of pending items in the queue. | |
| bool | empty (unsigned index) |
| Test if the queue is empty. | |
| bool | empty () |
| Test if the queue is empty. | |
Private Attributes | |
| Token | token_ |
| a unique allocation token that can be passed around to signal who owns the mutex. | |
Helper class that simulates a (non-reentrant) mutex using the Allocator queue and a single QueueMember token.
The mutex is defined as unlocked if there is an entry on the allocator queue. Locking the mutex will take the entry off of the allocator queue. Any other acquisition attempts will block so long as the allocator's queue is empty.
Unlocking the mutex will release the token back to the allocator, waking up the first caller in the queue.
To lock the mutex, use any allocation mechanism (e.g. control flow::Allocate, or SyncAllocator). To Unlock the mutex, call the Unlock method.
Definition at line 56 of file AsyncMutex.hxx.
|
inline |
Creates an allocator mutex.
Definition at line 60 of file AsyncMutex.hxx.
|
inline |
Definition at line 65 of file AsyncMutex.hxx.
|
inline |
Crashes if the mutex is not locked.
Definition at line 80 of file AsyncMutex.hxx.
|
inline |
Crashes if the mutex is locked.
Definition at line 86 of file AsyncMutex.hxx.
|
inline |
Crashes if the the particular value is not the token associated with this mutex.
| token | is the value to check. |
Definition at line 74 of file AsyncMutex.hxx.
|
inline |
Unlocks the mutex. Crashes if the mutex is unlocked.
Definition at line 92 of file AsyncMutex.hxx.
|
private |
a unique allocation token that can be passed around to signal who owns the mutex.
Definition at line 110 of file AsyncMutex.hxx.