Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
AsyncMutex.hxx
Go to the documentation of this file.
1
35#ifndef _UTILS_ASYNCMUTEX_HXX_
36#define _UTILS_ASYNCMUTEX_HXX_
37
38#include "utils/Queue.hxx"
39
56class AsyncMutex : public QAsync
57{
58public:
61 {
62 Unlock();
63 }
64
66 {
67 }
68
72 //
74 void CheckToken(QMember *token)
75 {
76 HASSERT(token == &token_);
77 }
78
81 {
82 HASSERT(empty());
83 }
84
87 {
88 HASSERT(!empty());
89 }
90
92 void Unlock()
93 {
95 insert(&token_);
96 }
97
106private:
107 class Token : public QMember {};
111};
112
113#endif // _UTILS_ASYNCMUTEX_HXX_
Synchronously locks the mutex.
Helper class that simulates a (non-reentrant) mutex using the Allocator queue and a single QueueMembe...
void CheckToken(QMember *token)
Crashes if the the particular value is not the token associated with this mutex.
void Unlock()
Unlocks the mutex. Crashes if the mutex is unlocked.
void AssertLocked()
Crashes if the mutex is not locked.
Token token_
a unique allocation token that can be passed around to signal who owns the mutex.
void AssertUnlocked()
Crashes if the mutex is locked.
AsyncMutex()
Creates an allocator mutex.
Asynchronous specialization of Q.
Definition Queue.hxx:254
bool empty()
Test if the queue is empty.
Definition Queue.hxx:388
void insert(QMember *item, unsigned index=0)
Add an item to the back of the queue.
Definition Queue.hxx:273
Essentially a "next" pointer container.
Definition QMember.hxx:42
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
Definition macros.h:138