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