#include <userver/engine/single_consumer_event.hpp>
A multiple-producers, single-consumer event.
Definition at line 19 of file single_consumer_event.hpp.
Classes | |
struct | NoAutoReset |
Public Member Functions | |
SingleConsumerEvent () noexcept | |
Creates an event that resets automatically on retrieval. | |
SingleConsumerEvent (NoAutoReset) noexcept | |
Creates an event that does not reset automatically. | |
SingleConsumerEvent (const SingleConsumerEvent &)=delete | |
SingleConsumerEvent (SingleConsumerEvent &&)=delete | |
SingleConsumerEvent & | operator= (const SingleConsumerEvent &)=delete |
SingleConsumerEvent & | operator= (SingleConsumerEvent &&)=delete |
bool | IsAutoReset () const noexcept |
bool | WaitForEvent () |
Waits until the event is in a signaled state. | |
template<typename Clock, typename Duration> | |
bool | WaitForEventFor (std::chrono::duration< Clock, Duration >) |
template<typename Clock, typename Duration> | |
bool | WaitForEventUntil (std::chrono::time_point< Clock, Duration >) |
bool | WaitForEventUntil (Deadline) |
bool | IsReady () const noexcept |
Works like std::condition_variable::wait_until . Waits until stop_waiting becomes true , and we are notified via Send . | |
|
noexcept |
|
nodiscardnoexcept |
Works like std::condition_variable::wait_until
. Waits until stop_waiting becomes true
, and we are notified via Send
.
If stop_waiting` is already true
, returns right away. / / Unlike std::condition_variable
and engine::ConditionVariable, there are / no locks around the state watched by stop_waiting, so that state must / be atomic. std::memory_order_relaxed
is OK inside stop_waiting and / inside the notifiers as long as it does not mess up their logic. / / Example. Suppose we want to wait until a counter is even, then grab / it. / / Initialization: /
/ / Notifier side: /
/ / Waiter side: /
template <typename Predicate> [[nodiscard]] bool WaitUntil(Deadline, Predicate stop_waiting);
/ Resets the signal flag. Guarantees at least 'acquire' and 'release' / memory ordering. Must only be called by the waiting task. void Reset() noexcept;
/ Sets the signal flag and wakes a coroutine that waits on it (if any). / If the signal flag is already set, does nothing. / / The waiter is allowed to destroy the SingleConsumerEvent immediately / after exiting WaitForEvent, ONLY IF the wait succeeded. Otherwise / a concurrent task may call Send on a destroyed SingleConsumerEvent. / Here is an example of this situation: /
void Send();
/ Returns true
iff already signaled. Never resets the signal.
|
nodiscard |
Waits until the event is in a signaled state.
If the event is auto-resetting, clears the signal flag upon waking up. If already in a signaled state, does the same without sleeping.
If we the waiting failed (the event did not signal), because the optional deadline is expired or the current task is cancelled, returns false
.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
nodiscard |
Definition at line 113 of file single_consumer_event.hpp.
|
nodiscard |
Definition at line 118 of file single_consumer_event.hpp.