rippled
Classes | Public Types | Public Member Functions | Private Types | Private Attributes | List of all members
ripple::test::csf::Scheduler Class Reference

Simulated discrete-event scheduler. More...

Collaboration diagram for ripple::test::csf::Scheduler:
Collaboration graph
[legend]

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
 
Scheduleroperator= (Scheduler const &)=delete
 
 Scheduler ()
 
clock_typeclock () 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_
 

Detailed Description

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.

Member Typedef Documentation

◆ clock_type

Definition at line 50 of file test/csf/Scheduler.h.

◆ duration

Definition at line 52 of file test/csf/Scheduler.h.

◆ time_point

Definition at line 54 of file test/csf/Scheduler.h.

◆ by_when_hook

using ripple::test::csf::Scheduler::by_when_hook = boost::intrusive::set_base_hook< boost::intrusive::link_mode<boost::intrusive::normal_link> >
private

Definition at line 58 of file test/csf/Scheduler.h.

Constructor & Destructor Documentation

◆ Scheduler() [1/2]

ripple::test::csf::Scheduler::Scheduler ( Scheduler const &  )
delete

◆ Scheduler() [2/2]

ripple::test::csf::Scheduler::Scheduler ( )

Definition at line 354 of file test/csf/Scheduler.h.

Member Function Documentation

◆ operator=()

Scheduler& ripple::test::csf::Scheduler::operator= ( Scheduler const &  )
delete

◆ clock()

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.

◆ now()

auto ripple::test::csf::Scheduler::now ( ) const

Return the current network time.

Note
The epoch is unspecified

Definition at line 365 of file test/csf/Scheduler.h.

◆ at() [1/2]

template<class Function >
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.

◆ in() [1/2]

template<class Function >
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.

◆ cancel()

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.

◆ step_one()

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.
Returns
true if an event was processed.

Definition at line 391 of file test/csf/Scheduler.h.

◆ step()

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.
Returns
true if an event was processed.

Definition at line 403 of file test/csf/Scheduler.h.

◆ step_while()

template<class Function >
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.
Returns
true if any event was processed.

Definition at line 415 of file test/csf/Scheduler.h.

◆ step_until()

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.
Returns
true if any event remain.

Definition at line 424 of file test/csf/Scheduler.h.

◆ step_for()

template<class Period , class Rep >
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.
Returns
true if any event remain.

Definition at line 449 of file test/csf/Scheduler.h.

◆ at() [2/2]

template<class Function >
auto ripple::test::csf::Scheduler::at ( time_point const &  when,
Function &&  f 
) -> cancel_token

Definition at line 372 of file test/csf/Scheduler.h.

◆ in() [2/2]

template<class Function >
auto ripple::test::csf::Scheduler::in ( duration const &  delay,
Function &&  f 
) -> cancel_token

Definition at line 379 of file test/csf/Scheduler.h.

Member Data Documentation

◆ alloc_

boost::container::pmr::monotonic_buffer_resource ripple::test::csf::Scheduler::alloc_ {kilobytes(256)}
private

Definition at line 148 of file test/csf/Scheduler.h.

◆ queue_

queue_type ripple::test::csf::Scheduler::queue_
private

Definition at line 149 of file test/csf/Scheduler.h.

◆ clock_

clock_type ripple::test::csf::Scheduler::clock_
mutableprivate

Definition at line 152 of file test/csf/Scheduler.h.