Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
AsyncMutex Class Reference

Helper class that simulates a (non-reentrant) mutex using the Allocator queue and a single QueueMember token. More...

#include <AsyncMutex.hxx>

Inheritance diagram for AsyncMutex:
QAsync

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.
 
QMembernext (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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ AsyncMutex()

AsyncMutex::AsyncMutex ( )
inline

Creates an allocator mutex.

Definition at line 60 of file AsyncMutex.hxx.

◆ ~AsyncMutex()

AsyncMutex::~AsyncMutex ( )
inline

Definition at line 65 of file AsyncMutex.hxx.

Member Function Documentation

◆ AssertLocked()

void AsyncMutex::AssertLocked ( )
inline

Crashes if the mutex is not locked.

Definition at line 80 of file AsyncMutex.hxx.

◆ AssertUnlocked()

void AsyncMutex::AssertUnlocked ( )
inline

Crashes if the mutex is locked.

Definition at line 86 of file AsyncMutex.hxx.

◆ CheckToken()

void AsyncMutex::CheckToken ( QMember token)
inline

Crashes if the the particular value is not the token associated with this mutex.

Parameters
tokenis the value to check.

Definition at line 74 of file AsyncMutex.hxx.

◆ Unlock()

void AsyncMutex::Unlock ( )
inline

Unlocks the mutex. Crashes if the mutex is unlocked.

Definition at line 92 of file AsyncMutex.hxx.

Member Data Documentation

◆ token_

Token AsyncMutex::token_
private

a unique allocation token that can be passed around to signal who owns the mutex.

Definition at line 110 of file AsyncMutex.hxx.


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