Seastar
High performance C++ framework for concurrent servers
Classes | Public Member Functions | List of all members
seastar::condition_variable Class Reference

Detailed Description

Conditional variable.

This is a standard computer science condition variable sans locking, since in seastar access to variables is atomic anyway, adapted for futures. You can wait for variable to be notified.

To support exceptional conditions, a broken() method is provided, which causes all current waiters to stop waiting, with an exceptional future returned. This allows causing all fibers that are blocked on a condition variable to continue. This issimilar to POSIX's pthread_cancel(), with wait() acting as a cancellation point.

#include <seastar/core/condition-variable.hh>

Public Member Functions

 condition_variable () noexcept=default
 
 condition_variable (condition_variable &&rhs) noexcept=default
 
future wait () noexcept
 
template<typename Clock = typename timer<>::clock, typename Duration = typename Clock::duration>
future wait (std::chrono::time_point< Clock, Duration > timeout) noexcept
 
template<typename Rep , typename Period >
future wait (std::chrono::duration< Rep, Period > timeout) noexcept
 
template<typename Pred >
future wait (Pred &&pred) noexcept
 
template<typename Clock = typename timer<>::clock, typename Duration = typename Clock::duration, typename Pred >
future wait (std::chrono::time_point< Clock, Duration > timeout, Pred &&pred) noexcept
 
template<typename Rep , typename Period , typename Pred >
future wait (std::chrono::duration< Rep, Period > timeout, Pred &&pred) noexcept
 
bool has_waiters () const noexcept
 
void signal () noexcept
 Notify variable and wake up a waiter if there is one.
 
void broadcast () noexcept
 Notify variable and wake up all waiter.
 
void broken () noexcept
 
void broken (std::exception_ptr) noexcept
 

Constructor & Destructor Documentation

◆ condition_variable()

seastar::condition_variable::condition_variable ( )
defaultnoexcept

Constructs a condition_variable object. Initialzie the semaphore with a default value of 0 to enusre the first call to wait() before signal() won't be waken up immediately.

Member Function Documentation

◆ broken()

void seastar::condition_variable::broken ( )
noexcept

Signal to waiters that an error occurred. wait() will see an exceptional future<> containing the provided exception parameter. The future is made available immediately.

◆ has_waiters()

bool seastar::condition_variable::has_waiters ( ) const
inlinenoexcept

Whether or not the condition variable currently has pending waiter(s) The returned answer is valid until next continuation/fiber switch.

◆ wait() [1/6]

future seastar::condition_variable::wait ( )
inlinenoexcept

Waits until condition variable is signaled, may wake up without condition been met

Returns
a future that becomes ready when signal() is called If the condition variable was broken() will return broken_condition_variable exception.

◆ wait() [2/6]

template<typename Pred >
future seastar::condition_variable::wait ( Pred &&  pred)
inlinenoexcept

Waits until condition variable is notified and pred() == true, otherwise wait again.

Parameters
predpredicate that checks that awaited condition is true
Returns
a future that becomes ready when signal() is called If the condition variable was broken(), may contain an exception.

◆ wait() [3/6]

template<typename Rep , typename Period >
future seastar::condition_variable::wait ( std::chrono::duration< Rep, Period >  timeout)
inlinenoexcept

Waits until condition variable is signaled or timeout is reached

Parameters
timeoutduration after which wait will exit with a timeout
Returns
a future that becomes ready when signal() is called If the condition variable was broken() will return broken_condition_variable exception. If timepoint is passed will return condition_variable_timed_out exception.

◆ wait() [4/6]

template<typename Rep , typename Period , typename Pred >
future seastar::condition_variable::wait ( std::chrono::duration< Rep, Period >  timeout,
Pred &&  pred 
)
inlinenoexcept

Waits until condition variable is notified and pred() == true or timeout is reached, otherwise wait again.

Parameters
timeoutduration after which wait will exit with a timeout
predpredicate that checks that awaited condition is true
Returns
a future that becomes ready when signal() is called If the condition variable was broken() will return broken_condition_variable exception. If timepoint is passed will return condition_variable_timed_out exception.

◆ wait() [5/6]

template<typename Clock = typename timer<>::clock, typename Duration = typename Clock::duration>
future seastar::condition_variable::wait ( std::chrono::time_point< Clock, Duration >  timeout)
inlinenoexcept

Waits until condition variable is signaled or timeout is reached

Parameters
timeouttime point at which wait will exit with a timeout
Returns
a future that becomes ready when signal() is called If the condition variable was broken() will return broken_condition_variable exception. If timepoint is reached will return condition_variable_timed_out exception.

◆ wait() [6/6]

template<typename Clock = typename timer<>::clock, typename Duration = typename Clock::duration, typename Pred >
future seastar::condition_variable::wait ( std::chrono::time_point< Clock, Duration >  timeout,
Pred &&  pred 
)
inlinenoexcept

Waits until condition variable is notified and pred() == true or timeout is reached, otherwise wait again.

Parameters
timeouttime point at which wait will exit with a timeout
predpredicate that checks that awaited condition is true
Returns
a future that becomes ready when signal() is called If the condition variable was broken() will return broken_condition_variable exception. If timepoint is reached will return condition_variable_timed_out exception.

The documentation for this class was generated from the following file: