CppCommon  1.0.4.1
C++ Common Library
named_event_auto_reset.h
Go to the documentation of this file.
1 
9 #ifndef CPPCOMMON_THREADS_NAMED_EVENT_AUTO_RESET_H
10 #define CPPCOMMON_THREADS_NAMED_EVENT_AUTO_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 NamedEventAutoReset(const std::string& name, bool signaled = false);
40 
43 
45  const std::string& name() const;
46 
48 
54  void Signal();
55 
57 
62  bool TryWait();
63 
65 
71  bool TryWaitFor(const Timespan& timespan);
73 
79  bool TryWaitUntil(const UtcTimestamp& timestamp)
80  { return TryWaitFor(timestamp - UtcTimestamp()); }
81 
83 
86  void Wait();
87 
88 private:
89  class Impl;
90 
91  Impl& impl() noexcept { return reinterpret_cast<Impl&>(_storage); }
92  const Impl& impl() const noexcept { return reinterpret_cast<Impl const&>(_storage); }
93 
94  static const size_t StorageSize = 136;
95  static const size_t StorageAlign = 8;
96  alignas(StorageAlign) std::byte _storage[StorageSize];
97 };
98 
101 } // namespace CppCommon
102 
103 #endif // CPPCOMMON_THREADS_NAMED_EVENT_AUTO_RESET_H
Named auto-reset event synchronization primitive.
const std::string & name() const
Get the event name.
NamedEventAutoReset & operator=(NamedEventAutoReset &&event)=delete
void Wait()
Try to wait the event with block.
NamedEventAutoReset & operator=(const NamedEventAutoReset &)=delete
bool TryWaitUntil(const UtcTimestamp &timestamp)
Try to wait the event until the given timestamp.
NamedEventAutoReset(const NamedEventAutoReset &)=delete
NamedEventAutoReset(const std::string &name, bool signaled=false)
Default class constructor.
void Signal()
Signal one of waiting thread about event occurred.
bool TryWait()
Try to wait the event without block.
bool TryWaitFor(const Timespan &timespan)
Try to wait the event for the given timespan.
NamedEventAutoReset(NamedEventAutoReset &&event)=delete
UTC timestamp.
Definition: timestamp.h:248
C++ Common project definitions.
Definition: token_bucket.h:15
Timestamp definition.