CppCommon 1.0.5.0
C++ Common Library
Loading...
Searching...
No Matches
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
17namespace CppCommon {
18
20
29{
30public:
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
88private:
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=(const NamedEventAutoReset &)=delete
void Wait()
Try to wait the event with block.
bool TryWaitUntil(const UtcTimestamp &timestamp)
Try to wait the event until the given timestamp.
NamedEventAutoReset(const NamedEventAutoReset &)=delete
void Signal()
Signal one of waiting thread about event occurred.
bool TryWait()
Try to wait the event without block.
NamedEventAutoReset & operator=(NamedEventAutoReset &&event)=delete
bool TryWaitFor(const Timespan &timespan)
Try to wait the event for the given timespan.
NamedEventAutoReset(NamedEventAutoReset &&event)=delete
C++ Common project definitions.
Timestamp definition.