blob: 572388a3ff0e5836a26179d9e2cda6358427c6ea (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
// Event.h
// Interfaces to the cEvent object representing a synchronization primitive that can be waited-for
// Implemented using C++11 condition variable and mutex
#pragma once
#include <mutex>
#include <condition_variable>
class cEvent
{
public:
cEvent(void);
/** Waits until the event has been set.
If the event has been set before it has been waited for, Wait() returns immediately. */
void Wait(void);
/** Sets the event - releases one thread that has been waiting in Wait().
If there was no thread waiting, the next call to Wait() will not block. */
void Set (void);
/** Waits for the event until either it is signalled, or the (relative) timeout is passed.
Returns true if the event was signalled, false if the timeout was hit or there was an error. */
bool Wait(unsigned a_TimeoutMSec);
private:
/** Used for checking for spurious wakeups. */
bool m_ShouldWait;
/** Mutex protecting m_ShouldWait from multithreaded access. */
std::mutex m_Mutex;
/** The condition variable used as the Event. */
std::condition_variable m_CondVar;
} ;
|