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 ()
 
future wait ()
 
future wait (time_point timeout)
 
future wait (duration timeout)
 
template<typename Pred >
future wait (Pred &&pred)
 
template<typename Pred >
future wait (time_point timeout, Pred &&pred)
 
template<typename Pred >
future wait (duration timeout, Pred &&pred)
 
void signal ()
 Notify variable and wake up a waiter if there is one.
 
void broadcast ()
 Notify variable and wake up all waiter.
 
void broken ()
 

Constructor & Destructor Documentation

◆ condition_variable()

seastar::condition_variable::condition_variable ( )
inline

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 ( )
inline

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

◆ wait() [1/6]

future seastar::condition_variable::wait ( )
inline

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]

future seastar::condition_variable::wait ( time_point  timeout)
inline

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() [3/6]

future seastar::condition_variable::wait ( duration  timeout)
inline

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 Pred >
future seastar::condition_variable::wait ( Pred &&  pred)
inline

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() [5/6]

template<typename Pred >
future seastar::condition_variable::wait ( time_point  timeout,
Pred &&  pred 
)
inline

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.
Parameters

◆ wait() [6/6]

template<typename Pred >
future seastar::condition_variable::wait ( duration  timeout,
Pred &&  pred 
)
inline

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.

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