xrpld
Loading...
Searching...
No Matches
xrpl::test::csf::Scheduler Class Reference

Simulated discrete-event scheduler. More...

#include <Scheduler.h>

Collaboration diagram for xrpl::test::csf::Scheduler:

Classes

struct  Event
class  EventImpl
class  QueueType
struct  CancelToken

Public Types

using clock_type = beast::ManualClock<std::chrono::steady_clock>
using duration = clock_type::duration
using time_point = clock_type::time_point

Public Member Functions

 Scheduler (Scheduler const &)=delete
Scheduleroperator= (Scheduler const &)=delete
 Scheduler ()
clock_typeclock () const
 Return the clock.
time_point now () const
 Return the current network time.
template<class Function>
CancelToken at (time_point const &when, Function &&f)
 Schedule an event at a specific time.
template<class Function>
CancelToken in (duration const &delay, Function &&f)
 Schedule an event after a specified duration passes.
void cancel (CancelToken const &token)
 Cancel a timer.
bool stepOne ()
 Run the scheduler for up to one event.
bool step ()
 Run the scheduler until no events remain.
template<class Function>
bool stepWhile (Function &&func)
 Run the scheduler while a condition is true.
bool stepUntil (time_point const &until)
 Run the scheduler until the specified time.
template<class Period, class Rep>
bool stepFor (std::chrono::duration< Period, Rep > const &amount)
 Run the scheduler until time has elapsed.

Private Types

using by_when_hook

Private Attributes

boost::container::pmr::monotonic_buffer_resource alloc_ {kilobytes(256)}
QueueType 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, stepOne, stepFor, stepUntil and stepWhile functions to process scheduled events.

Definition at line 25 of file src/test/csf/Scheduler.h.

Member Typedef Documentation

◆ clock_type

◆ duration

◆ time_point

◆ by_when_hook

Initial value:
boost::intrusive::set_base_hook<boost::intrusive::link_mode<boost::intrusive::normal_link>>

Definition at line 35 of file src/test/csf/Scheduler.h.

Constructor & Destructor Documentation

◆ Scheduler() [1/2]

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

◆ Scheduler() [2/2]

xrpl::test::csf::Scheduler::Scheduler ( )

Definition at line 328 of file src/test/csf/Scheduler.h.

Member Function Documentation

◆ operator=()

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

◆ clock()

auto xrpl::test::csf::Scheduler::clock ( ) const

Return the clock.

(aged_containers want a non-const ref =(

Definition at line 333 of file src/test/csf/Scheduler.h.

◆ now()

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

Return the current network time.

Note
The epoch is unspecified

Definition at line 339 of file src/test/csf/Scheduler.h.

◆ at()

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

Schedule an event at a specific time.

Effects:

When the network time is reached,
the function will be called with
no arguments.

Definition at line 346 of file src/test/csf/Scheduler.h.

◆ in()

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

Schedule an event after a specified duration passes.

Effects:

When the specified time has elapsed,
the function will be called with
no arguments.

Definition at line 353 of file src/test/csf/Scheduler.h.

◆ cancel()

void xrpl::test::csf::Scheduler::cancel ( CancelToken const & token)

Cancel a timer.

Preconditions:

`token` was the return value of a call
timer() which has not yet been invoked.

Definition at line 359 of file src/test/csf/Scheduler.h.

◆ stepOne()

bool xrpl::test::csf::Scheduler::stepOne ( )

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 365 of file src/test/csf/Scheduler.h.

◆ step()

bool xrpl::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 377 of file src/test/csf/Scheduler.h.

◆ stepWhile()

template<class Function>
bool xrpl::test::csf::Scheduler::stepWhile ( 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 391 of file src/test/csf/Scheduler.h.

◆ stepUntil()

bool xrpl::test::csf::Scheduler::stepUntil ( 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 400 of file src/test/csf/Scheduler.h.

◆ stepFor()

template<class Period, class Rep>
bool xrpl::test::csf::Scheduler::stepFor ( 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 425 of file src/test/csf/Scheduler.h.

Member Data Documentation

◆ alloc_

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

Definition at line 124 of file src/test/csf/Scheduler.h.

◆ queue_

QueueType xrpl::test::csf::Scheduler::queue_
private

Definition at line 125 of file src/test/csf/Scheduler.h.

◆ clock_

clock_type xrpl::test::csf::Scheduler::clock_
mutableprivate

Definition at line 128 of file src/test/csf/Scheduler.h.