3#include <condition_variable>
11
12
13
14
15
16
26 explicit Guard(Ptr gate) : gate_(std::move(gate))
29 Guard(
const Guard&) =
delete;
31 Guard(
Guard&&) =
delete;
46 const std::lock_guard lk(mutex_);
47 if(!accepting_callbacks_)
58 const std::lock_guard lk(mutex_);
59 accepting_callbacks_ =
false;
65 std::unique_lock lk(mutex_);
66 accepting_callbacks_ =
false;
67 condition_variable_.wait(lk, [
this] {
return running_callbacks_ == 0; });
73 const std::lock_guard lk(mutex_);
75 if(running_callbacks_ == 0 && !accepting_callbacks_)
77 condition_variable_.notify_all();
82 std::condition_variable condition_variable_;
83 bool accepting_callbacks_ =
true;
84 size_t running_callbacks_ = 0;
RAII helper that signals the completion of a callback entered with tryStart()
Definition: callback_gate.h:24
Synchronization gate used to coordinate callbacks with object teardown.
Definition: callback_gate.h:18
void close()
Reject new callbacks, without waiting for the running ones.
Definition: callback_gate.h:56
void closeAndDrain()
Reject new callbacks and wait until callbacks already running have completed.
Definition: callback_gate.h:63
bool tryStart()
Returns false if the gate has been closed and the callback must not run.
Definition: callback_gate.h:44
The SwitchNode is equivalent to a switch statement, where a certain branch (child) is executed accord...
Definition: basic_types.h:532
Definition: action_node.h:24