CppCommon  1.0.4.1
C++ Common Library
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 
16 namespace CppCommon {
17 
19 
29 {
30 public:
32 
35  explicit EventAutoReset(bool signaled = false);
36  EventAutoReset(const EventAutoReset&) = delete;
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 
84 private:
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=(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.
EventAutoReset(bool signaled=false)
Default class constructor.
bool TryWaitFor(const Timespan &timespan)
Try to wait the event for the given timespan.
EventAutoReset & operator=(EventAutoReset &&event)=delete
EventAutoReset(const EventAutoReset &)=delete
EventAutoReset(EventAutoReset &&event)=delete
UTC timestamp.
Definition: timestamp.h:248
C++ Common project definitions.
Definition: token_bucket.h:15
Timestamp definition.