3 #include "phonebook.hpp"
6 #include <condition_variable>
18 mutable std::mutex _m_mutex;
19 mutable std::condition_variable _m_cv;
20 std::atomic<bool> _m_value =
false;
28 void set(
bool new_value =
true) {
30 std::lock_guard lock{_m_mutex};
56 std::unique_lock<std::mutex> lock{_m_mutex};
61 _m_cv.wait(lock, [
this] {
62 return _m_value.load();
71 template<
class Clock,
class Rep,
class Period>
72 bool wait_timeout(
const std::chrono::duration<Rep, Period>& duration)
const {
73 auto timeout_time = Clock::now() + duration;
77 std::unique_lock<std::mutex> lock{_m_mutex};
78 while (_m_cv.wait_until(lock, timeout_time) != std::cv_status::timeout) {
108 void wait_for_ready()
const {
112 void signal_ready() {
116 bool check_should_stop()
const {
117 return _m_should_stop.
is_set();
120 void signal_should_stop() {
121 _m_should_stop.
set();
124 void wait_for_shutdown_complete()
const {
125 _m_shutdown_complete.
wait();
128 bool check_shutdown_complete()
const {
129 return _m_shutdown_complete.
is_set();
132 void signal_shutdown_complete() {
133 _m_shutdown_complete.
set();
138 Event _m_should_stop;
139 Event _m_shutdown_complete;
A boolean condition-variable.
Definition: stoplight.hpp:16
void clear()
Clears the condition-variable.
Definition: stoplight.hpp:41
bool wait_timeout(const std::chrono::duration< Rep, Period > &duration) const
Wait for the event to be set with a timeout.
Definition: stoplight.hpp:72
void set(bool new_value=true)
Sets the condition-variable to new_value.
Definition: stoplight.hpp:28
void wait() const
Wait indefinitely for the event to be set.
Definition: stoplight.hpp:55
bool is_set() const
Test if is set without blocking.
Definition: stoplight.hpp:48
Start/stop synchronization for the whole application.
Definition: stoplight.hpp:106
A 'service' that can be registered in the phonebook.
Definition: phonebook.hpp:86
RAC_ERRNO_MSG.
Definition: data_format.hpp:15