CppCommon 1.0.5.0
C++ Common Library
Loading...
Searching...
No Matches
event_auto_reset.h
Go to the documentation of this file.
1
9#ifndef CPPCOMMON_THREADS_EVENT_AUTO_RESET_H
10#define CPPCOMMON_THREADS_EVENT_AUTO_RESET_H
11
12#include "time/timestamp.h"
13
14#include <memory>
15
16namespace CppCommon {
17
19
29{
30public:
32
35 explicit EventAutoReset(bool signaled = false);
37 EventAutoReset(EventAutoReset&& event) = delete;
39
42
44
50 void Signal();
51
53
58 bool TryWait();
59
61
67 bool TryWaitFor(const Timespan& timespan);
69
75 bool TryWaitUntil(const UtcTimestamp& timestamp)
76 { return TryWaitFor(timestamp - UtcTimestamp()); }
77
79
82 void Wait();
83
84private:
85 class Impl;
86
87 Impl& impl() noexcept { return reinterpret_cast<Impl&>(_storage); }
88 const Impl& impl() const noexcept { return reinterpret_cast<Impl const&>(_storage); }
89
90 static const size_t StorageSize = 128;
91 static const size_t StorageAlign = 8;
92 alignas(StorageAlign) std::byte _storage[StorageSize];
93};
94
97} // namespace CppCommon
98
99#endif // CPPCOMMON_THREADS_EVENT_AUTO_RESET_H
Auto-reset event synchronization primitive.
bool TryWaitUntil(const UtcTimestamp &timestamp)
Try to wait the event until the given timestamp.
EventAutoReset & operator=(EventAutoReset &&event)=delete
EventAutoReset & operator=(const EventAutoReset &)=delete
bool TryWait()
Try to wait the event without block.
void Wait()
Try to wait the event with block.
void Signal()
Signal one of waiting thread about event occurred.
bool TryWaitFor(const Timespan &timespan)
Try to wait the event for the given timespan.
EventAutoReset(const EventAutoReset &)=delete
EventAutoReset(EventAutoReset &&event)=delete
C++ Common project definitions.
Timestamp definition.