rippled
|
Simulated discrete-event scheduler. More...
Classes | |
struct | cancel_token |
struct | event |
class | event_impl |
class | queue_type |
Public Types | |
using | clock_type = beast::manual_clock< std::chrono::steady_clock > |
using | duration = typename clock_type::duration |
using | time_point = typename clock_type::time_point |
Public Member Functions | |
Scheduler (Scheduler const &)=delete | |
Scheduler & | operator= (Scheduler const &)=delete |
Scheduler () | |
clock_type & | clock () const |
Return the clock. More... | |
time_point | now () const |
Return the current network time. More... | |
template<class Function > | |
cancel_token | at (time_point const &when, Function &&f) |
Schedule an event at a specific time. More... | |
template<class Function > | |
cancel_token | in (duration const &delay, Function &&f) |
Schedule an event after a specified duration passes. More... | |
void | cancel (cancel_token const &token) |
Cancel a timer. More... | |
bool | step_one () |
Run the scheduler for up to one event. More... | |
bool | step () |
Run the scheduler until no events remain. More... | |
template<class Function > | |
bool | step_while (Function &&func) |
Run the scheduler while a condition is true. More... | |
bool | step_until (time_point const &until) |
Run the scheduler until the specified time. More... | |
template<class Period , class Rep > | |
bool | step_for (std::chrono::duration< Period, Rep > const &amount) |
Run the scheduler until time has elapsed. More... | |
template<class Function > | |
auto | at (time_point const &when, Function &&f) -> cancel_token |
template<class Function > | |
auto | in (duration const &delay, Function &&f) -> cancel_token |
Private Types | |
using | by_when_hook = boost::intrusive::set_base_hook< boost::intrusive::link_mode< boost::intrusive::normal_link > > |
Private Attributes | |
boost::container::pmr::monotonic_buffer_resource | alloc_ {kilobytes(256)} |
queue_type | queue_ |
clock_type | clock_ |
Simulated discrete-event scheduler.
Simulates the behavior of events using a single common clock.
An event is modeled using a lambda function and is scheduled to occur at a specific time. Events may be canceled using a token returned when the event is scheduled.
The caller uses one or more of the step, step_one, step_for, step_until and step_while functions to process scheduled events.
Definition at line 47 of file test/csf/Scheduler.h.
Definition at line 50 of file test/csf/Scheduler.h.
using ripple::test::csf::Scheduler::duration = typename clock_type::duration |
Definition at line 52 of file test/csf/Scheduler.h.
using ripple::test::csf::Scheduler::time_point = typename clock_type::time_point |
Definition at line 54 of file test/csf/Scheduler.h.
|
private |
Definition at line 58 of file test/csf/Scheduler.h.
|
delete |
ripple::test::csf::Scheduler::Scheduler | ( | ) |
Definition at line 354 of file test/csf/Scheduler.h.
auto ripple::test::csf::Scheduler::clock | ( | ) | const |
Return the clock.
(aged_containers want a non-const ref =(
Definition at line 359 of file test/csf/Scheduler.h.
auto ripple::test::csf::Scheduler::now | ( | ) | const |
Return the current network time.
Definition at line 365 of file test/csf/Scheduler.h.
cancel_token ripple::test::csf::Scheduler::at | ( | time_point const & | when, |
Function && | f | ||
) |
Schedule an event at a specific time.
Effects:
When the network time is reached, the function will be called with no arguments.
cancel_token ripple::test::csf::Scheduler::in | ( | duration const & | delay, |
Function && | f | ||
) |
Schedule an event after a specified duration passes.
Effects:
When the specified time has elapsed, the function will be called with no arguments.
void ripple::test::csf::Scheduler::cancel | ( | cancel_token const & | token | ) |
Cancel a timer.
Preconditions:
`token` was the return value of a call timer() which has not yet been invoked.
Definition at line 385 of file test/csf/Scheduler.h.
bool ripple::test::csf::Scheduler::step_one | ( | ) |
Run the scheduler for up to one event.
Effects:
The clock is advanced to the time of the last delivered event.
true
if an event was processed. Definition at line 391 of file test/csf/Scheduler.h.
bool ripple::test::csf::Scheduler::step | ( | ) |
Run the scheduler until no events remain.
Effects:
The clock is advanced to the time of the last event.
true
if an event was processed. Definition at line 403 of file test/csf/Scheduler.h.
bool ripple::test::csf::Scheduler::step_while | ( | Function && | func | ) |
Run the scheduler while a condition is true.
Function takes no arguments and will be called repeatedly after each event is processed to decide whether to continue.
Effects:
The clock is advanced to the time of the last delivered event.
true
if any event was processed. Definition at line 415 of file test/csf/Scheduler.h.
bool ripple::test::csf::Scheduler::step_until | ( | time_point const & | until | ) |
Run the scheduler until the specified time.
Effects:
The clock is advanced to the specified time.
true
if any event remain. Definition at line 424 of file test/csf/Scheduler.h.
bool ripple::test::csf::Scheduler::step_for | ( | std::chrono::duration< Period, Rep > const & | amount | ) |
Run the scheduler until time has elapsed.
Effects:
The clock is advanced by the specified duration.
true
if any event remain. Definition at line 449 of file test/csf/Scheduler.h.
auto ripple::test::csf::Scheduler::at | ( | time_point const & | when, |
Function && | f | ||
) | -> cancel_token |
Definition at line 372 of file test/csf/Scheduler.h.
auto ripple::test::csf::Scheduler::in | ( | duration const & | delay, |
Function && | f | ||
) | -> cancel_token |
Definition at line 379 of file test/csf/Scheduler.h.
|
private |
Definition at line 148 of file test/csf/Scheduler.h.
|
private |
Definition at line 149 of file test/csf/Scheduler.h.
|
mutableprivate |
Definition at line 152 of file test/csf/Scheduler.h.