Async 1.8.0
AsyncMutex.h
Go to the documentation of this file.
1
31#ifndef ASYNC_MUTEX_INCLUDED
32#define ASYNC_MUTEX_INCLUDED
33
34/****************************************************************************
35 *
36 * System Includes
37 *
38 ****************************************************************************/
39
40#include <mutex>
41#include <condition_variable>
42
43
44/****************************************************************************
45 *
46 * Project Includes
47 *
48 ****************************************************************************/
49
50
51
52/****************************************************************************
53 *
54 * Local Includes
55 *
56 ****************************************************************************/
57
58
59
60/****************************************************************************
61 *
62 * Forward declarations
63 *
64 ****************************************************************************/
65
66
67
68/****************************************************************************
69 *
70 * Namespace
71 *
72 ****************************************************************************/
73
74namespace Async
75{
76
77
78/****************************************************************************
79 *
80 * Forward declarations of classes inside of the declared namespace
81 *
82 ****************************************************************************/
83
84
85
86/****************************************************************************
87 *
88 * Defines & typedefs
89 *
90 ****************************************************************************/
91
92
93
94/****************************************************************************
95 *
96 * Exported Global Variables
97 *
98 ****************************************************************************/
99
100
101
102/****************************************************************************
103 *
104 * Class definitions
105 *
106 ****************************************************************************/
107
142class Mutex
143{
144 public:
153 Mutex(void) noexcept;
154
158 Mutex(const Mutex&) = delete;
159
168 ~Mutex(void);
169
173 Mutex& operator=(const Mutex&) = delete;
174
184 void lock(void);
185
186 //bool try_lock() { return mu.try_lock(); }
187
196 void unlock(void);
197
198 private:
199 static std::mutex mu;
200 static std::condition_variable lock_available_cond;
201 static std::condition_variable no_locks_waiting_cond;
202 static std::thread::id main_thread;
203 static std::thread::id lock_owner;
204 static size_t lock_wait_cnt;
205 static bool lock_handler_pending;
206
207 static void lockHandler(void);
208 static void mainThreadDone(void);
209
210}; /* class Mutex */
211
212
213} /* namespace */
214
215#endif /* ASYNC_MUTEX_INCLUDED */
216
217/*
218 * This file has not been truncated
219 */
Synchronize execution from a thread with the main Async thread.
Definition AsyncMutex.h:143
void unlock(void)
Unlock the mutex.
Mutex & operator=(const Mutex &)=delete
Assignment operator is deleted.
Mutex(const Mutex &)=delete
Copy constructor is deleted.
Mutex(void) noexcept
Default constructor.
void lock(void)
Lock the mutex.
~Mutex(void)
Destructor.
Namespace for the asynchronous programming classes.