20#ifndef RIPPLE_TEST_CSF_SCHEDULER_H_INCLUDED
21#define RIPPLE_TEST_CSF_SCHEDULER_H_INCLUDED
23#include <xrpl/basics/ByteUtilities.h>
24#include <xrpl/beast/clock/manual_clock.h>
26#include <boost/container/pmr/monotonic_buffer_resource.hpp>
27#include <boost/intrusive/set.hpp>
58 boost::intrusive::link_mode<boost::intrusive::normal_link>>;
85 template <
class Handler>
96 template <
class DeducedHandler>
114 boost::intrusive::constant_time_size<false>>::type;
116 boost::container::pmr::monotonic_buffer_resource*
alloc_;
127 boost::container::pmr::monotonic_buffer_resource* alloc);
140 template <
class Handler>
141 typename by_when_set::iterator
183 template <
class Function>
195 template <
class Function>
246 template <
class Function>
271 template <
class Period,
class Rep>
279 boost::container::pmr::monotonic_buffer_resource* alloc)
286 for (
auto iter = by_when_.begin(); iter != by_when_.end();)
291 alloc_->deallocate(e,
sizeof(e));
298 return by_when_.empty();
304 return by_when_.begin();
310 return by_when_.end();
313template <
class Handler>
316 typename by_when_set::iterator
319 auto const p =
alloc_->allocate(
sizeof(event_type));
321 return by_when_.insert(e);
328 auto next = by_when_.erase(iter);
330 alloc_->deallocate(&e,
sizeof(e));
370template <
class Function>
377template <
class Function>
413template <
class Function>
433 if (iter->when > until)
442 }
while (iter !=
queue_.
end() && iter->when <= until);
447template <
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