CppCommon  1.0.4.1
C++ Common Library
event_manual_reset.h
Go to the documentation of this file.
1 
9 #ifndef CPPCOMMON_THREADS_EVENT_MANUAL_RESET_H
10 #define CPPCOMMON_THREADS_EVENT_MANUAL_RESET_H
11 
12 #include "time/timestamp.h"
13 
14 #include <memory>
15 
16 namespace CppCommon {
17 
19 
29 {
30 public:
32 
35  explicit EventManualReset(bool signaled = false);
39 
42 
44 
50  void Reset();
51 
53 
58  void Signal();
59 
61 
66  bool TryWait();
67 
69 
75  bool TryWaitFor(const Timespan& timespan);
77 
83  bool TryWaitUntil(const UtcTimestamp& timestamp)
84  { return TryWaitFor(timestamp - UtcTimestamp()); }
85 
87 
90  void Wait();
91 
92 private:
93  class Impl;
94 
95  Impl& impl() noexcept { return reinterpret_cast<Impl&>(_storage); }
96  const Impl& impl() const noexcept { return reinterpret_cast<Impl const&>(_storage); }
97 
98  static const size_t StorageSize = 128;
99  static const size_t StorageAlign = 8;
100  alignas(StorageAlign) std::byte _storage[StorageSize];
101 };
102 
105 } // namespace CppCommon
106 
107 #endif // CPPCOMMON_THREADS_EVENT_MANUAL_RESET_H
Manual-reset event synchronization primitive.
bool TryWait()
Try to wait the event without block.
void Reset()
Reset the event.
EventManualReset(EventManualReset &&event)=delete
EventManualReset & operator=(const EventManualReset &)=delete
bool TryWaitFor(const Timespan &timespan)
Try to wait the event for the given timespan.
EventManualReset(const EventManualReset &)=delete
EventManualReset & operator=(EventManualReset &&event)=delete
bool TryWaitUntil(const UtcTimestamp &timestamp)
Try to wait the event until the given timestamp.
EventManualReset(bool signaled=false)
Default class constructor.
void Wait()
Try to wait the event with block.
void Signal()
Signal one of waiting thread about event occurred.
UTC timestamp.
Definition: timestamp.h:248
C++ Common project definitions.
Definition: token_bucket.h:15
Timestamp definition.