-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEvent.h
More file actions
43 lines (34 loc) · 923 Bytes
/
Event.h
File metadata and controls
43 lines (34 loc) · 923 Bytes
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
#pragma once
#ifndef _WIN32
#include <condition_variable>
#include <mutex>
#endif
NS_BEGIN
static constexpr auto INFINITE_WAIT = (size_t)-1;
//#################################################################################################
class CEvent final
{
public:
explicit CEvent(const bool bSignaled = false);
CEvent(const CEvent &src) = delete;
CEvent(CEvent &&src) = delete;
~CEvent(void);
CEvent &operator=(const CEvent &src) = delete;
CEvent &operator=(CEvent &&src) = delete;
void Signal(void);
void Reset(void);
// Waits for the event to be signaled, returns true if signaled or false if timed out
bool Wait(const size_t nMilliseconds = INFINITE_WAIT);
#ifdef _WIN32
operator HANDLE(void) const noexcept;
#endif
private:
#ifdef _WIN32
HANDLE m_hEvent;
#else
std::condition_variable m_cv;
std::mutex m_mutex;
bool m_bSignaled;
#endif
};
NS_END