1#ifndef XRPL_TEST_CSF_SCHEDULER_H_INCLUDED
2#define XRPL_TEST_CSF_SCHEDULER_H_INCLUDED
4#include <xrpl/basics/ByteUtilities.h>
5#include <xrpl/beast/clock/manual_clock.h>
7#include <boost/container/pmr/monotonic_buffer_resource.hpp>
8#include <boost/intrusive/set.hpp>
39 boost::intrusive::link_mode<boost::intrusive::normal_link>>;
66 template <
class Handler>
77 template <
class DeducedHandler>
95 boost::intrusive::constant_time_size<false>>::type;
97 boost::container::pmr::monotonic_buffer_resource*
alloc_;
108 boost::container::pmr::monotonic_buffer_resource* alloc);
121 template <
class Handler>
122 typename by_when_set::iterator
164 template <
class Function>
176 template <
class Function>
227 template <
class Function>
252 template <
class Period,
class Rep>
260 boost::container::pmr::monotonic_buffer_resource* alloc)
267 for (
auto iter = by_when_.begin(); iter != by_when_.end();)
272 alloc_->deallocate(e,
sizeof(e));
279 return by_when_.empty();
285 return by_when_.begin();
291 return by_when_.end();
294template <
class Handler>
297 typename by_when_set::iterator
300 auto const p =
alloc_->allocate(
sizeof(event_type));
302 return by_when_.insert(e);
309 auto next = by_when_.erase(iter);
311 alloc_->deallocate(&e,
sizeof(e));
351template <
class Function>
358template <
class Function>
394template <
class Function>
414 if (iter->when > until)
423 }
while (iter !=
queue_.
end() && iter->when <= until);
428template <
class Period,
class Rep>
typename Clock::time_point time_point
typename Clock::duration duration
time_point now() const override
Returns the current time.
void set(time_point const &when)
Set the current time of the manual clock.
event_impl(time_point when_, DeducedHandler &&h)
event_impl & operator=(event_impl const &)=delete
event_impl(event_impl const &)=delete
void operator()() const override
typename boost::intrusive::make_multiset< event, boost::intrusive::constant_time_size< false > >::type by_when_set
iterator erase(iterator iter)
queue_type(queue_type const &)=delete
typename by_when_set::iterator iterator
by_when_set::iterator emplace(time_point when, Handler &&h)
queue_type & operator=(queue_type const &)=delete
boost::container::pmr::monotonic_buffer_resource * alloc_
Simulated discrete-event scheduler.
Scheduler & operator=(Scheduler const &)=delete
bool step_one()
Run the scheduler for up to one event.
bool step_while(Function &&func)
Run the scheduler while a condition is true.
typename clock_type::duration duration
cancel_token at(time_point const &when, Function &&f)
Schedule an event at a specific time.
typename clock_type::time_point time_point
bool step_for(std::chrono::duration< Period, Rep > const &amount)
Run the scheduler until time has elapsed.
boost::container::pmr::monotonic_buffer_resource alloc_
time_point now() const
Return the current network time.
bool step_until(time_point const &until)
Run the scheduler until the specified time.
clock_type & clock() const
Return the clock.
boost::intrusive::set_base_hook< boost::intrusive::link_mode< boost::intrusive::normal_link > > by_when_hook
Scheduler(Scheduler const &)=delete
void cancel(cancel_token const &token)
Cancel a timer.
bool step()
Run the scheduler until no events remain.
cancel_token in(duration const &delay, Function &&f)
Schedule an event after a specified duration passes.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
constexpr auto kilobytes(T value) noexcept
cancel_token & operator=(cancel_token const &)=default
cancel_token(typename queue_type::iterator iter)
queue_type::iterator iter_
cancel_token(cancel_token const &)=default
event(event const &)=delete
event & operator=(event const &)=delete
virtual void operator()() const =0
bool operator<(event const &other) const