Skip to content

Commit 413b36c

Browse files
committed
s
1 parent fa11b1a commit 413b36c

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

modules/Thread/Event.mpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
export module CppUtils.Thread.Event;
2+
3+
import std;
4+
5+
export namespace CppUtils::Thread
6+
{
7+
class Event final
8+
{
9+
public:
10+
void wait()
11+
{
12+
auto lock = std::unique_lock{m_mutex};
13+
m_conditionVariable.wait(lock, [this]() { return m_triggered; });
14+
m_triggered = false;
15+
}
16+
17+
void notify()
18+
{
19+
{
20+
auto lock = std::unique_lock{m_mutex};
21+
m_triggered = true;
22+
}
23+
m_conditionVariable.notify_all();
24+
}
25+
26+
void reset()
27+
{
28+
auto lock = std::unique_lock{m_mutex};
29+
m_triggered = false;
30+
}
31+
32+
private:
33+
std::mutex m_mutex;
34+
std::condition_variable m_conditionVariable;
35+
bool m_triggered = false;
36+
};
37+
}

0 commit comments

Comments
 (0)