CppCommon  1.0.4.1
C++ Common Library
named_event_manual_reset.h
Go to the documentation of this file.
1 
9 #ifndef CPPCOMMON_THREADS_NAMED_EVENT_MANUAL_RESET_H
10 #define CPPCOMMON_THREADS_NAMED_EVENT_MANUAL_RESET_H
11 
12 #include "time/timestamp.h"
13 
14 #include <memory>
15 #include <string>
16 
17 namespace CppCommon {
18 
20 
29 {
30 public:
32 
36  explicit NamedEventManualReset(const std::string& name, bool signaled = false);
40 
43 
45  const std::string& name() const;
46 
48 
54  void Reset();
55 
57 
62  void Signal();
63 
65 
70  bool TryWait();
71 
73 
79  bool TryWaitFor(const Timespan& timespan);
81 
87  bool TryWaitUntil(const UtcTimestamp& timestamp)
88  { return TryWaitFor(timestamp - UtcTimestamp()); }
89 
91 
94  void Wait();
95 
96 private:
97  class Impl;
98 
99  Impl& impl() noexcept { return reinterpret_cast<Impl&>(_storage); }
100  const Impl& impl() const noexcept { return reinterpret_cast<Impl const&>(_storage); }
101 
102  static const size_t StorageSize = 136;
103  static const size_t StorageAlign = 8;
104  alignas(StorageAlign) std::byte _storage[StorageSize];
105 };
106 
109 } // namespace CppCommon
110 
111 #endif // CPPCOMMON_THREADS_NAMED_EVENT_MANUAL_RESET_H
Named manual-reset event synchronization primitive.
void Signal()
Signal one of waiting thread about event occurred.
NamedEventManualReset & operator=(const NamedEventManualReset &)=delete
bool TryWaitUntil(const UtcTimestamp &timestamp)
Try to wait the event until the given timestamp.
const std::string & name() const
Get the event name.
NamedEventManualReset & operator=(NamedEventManualReset &&event)=delete
void Wait()
Try to wait the event with block.
NamedEventManualReset(const std::string &name, bool signaled=false)
Default class constructor.
bool TryWait()
Try to wait the event without block.
NamedEventManualReset(const NamedEventManualReset &)=delete
NamedEventManualReset(NamedEventManualReset &&event)=delete
bool TryWaitFor(const Timespan &timespan)
Try to wait the event for the given timespan.
UTC timestamp.
Definition: timestamp.h:248
C++ Common project definitions.
Definition: token_bucket.h:15
Timestamp definition.