-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEvent.mpp
More file actions
51 lines (44 loc) · 1.16 KB
/
Copy pathEvent.mpp
File metadata and controls
51 lines (44 loc) · 1.16 KB
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
export module CppUtils.Execution.Event;
import std;
import CppUtils.Chrono.Concept;
export namespace CppUtils::Execution
{
class Event final
{
public:
inline auto wait() -> void
{
auto lock = std::unique_lock{m_mutex};
m_conditionVariable.wait(lock, [this] { return m_triggered; });
}
template<Chrono::Duration DurationType>
[[nodiscard]] inline auto waitFor(const DurationType& duration) -> bool
{
auto lock = std::unique_lock{m_mutex};
return m_conditionVariable.wait_for(lock, duration, [this] { return m_triggered; });
}
template<Chrono::TimePoint TimePointType>
[[nodiscard]] inline auto waitUntil(const TimePointType& timePoint) -> bool
{
auto lock = std::unique_lock{m_mutex};
return m_conditionVariable.wait_until(lock, timePoint, [this] { return m_triggered; });
}
inline auto notify() -> void
{
{
auto lock = std::lock_guard{m_mutex};
m_triggered = true;
}
m_conditionVariable.notify_all();
}
inline auto reset() -> void
{
auto lock = std::lock_guard{m_mutex};
m_triggered = false;
}
private:
std::mutex m_mutex;
std::condition_variable m_conditionVariable;
bool m_triggered = false;
};
}