3#include <xrpl/basics/ByteUtilities.h>
4#include <xrpl/beast/clock/manual_clock.h>
6#include <boost/container/pmr/monotonic_buffer_resource.hpp>
7#include <boost/intrusive/set.hpp>
37 using by_when_hook = boost::intrusive::set_base_hook<boost::intrusive::link_mode<boost::intrusive::normal_link>>;
64 template <
class Handler>
75 template <
class DeducedHandler>
91 typename boost::intrusive::make_multiset<event, boost::intrusive::constant_time_size<false>>::type;
93 boost::container::pmr::monotonic_buffer_resource*
alloc_;
97 using iterator =
typename by_when_set::iterator;
103 explicit queue_type(boost::container::pmr::monotonic_buffer_resource* alloc);
116 template <
class Handler>
117 typename by_when_set::iterator
159 template <
class Function>
171 template <
class Function>
222 template <
class Function>
247 template <
class Period,
class Rep>
260 for (
auto iter = by_when_.begin(); iter != by_when_.end();)
265 alloc_->deallocate(e,
sizeof(e));
272 return by_when_.empty();
278 return by_when_.begin();
284 return by_when_.end();
287template <
class Handler>
292 auto const p =
alloc_->allocate(
sizeof(event_type));
294 return by_when_.insert(e);
301 auto next = by_when_.erase(iter);
303 alloc_->deallocate(&e,
sizeof(e));
343template <
class Function>
350template <
class Function>
386template <
class Function>
406 if (iter->when > until)
415 }
while (iter !=
queue_.
end() && iter->when <= until);
420template <
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 & operator=(event_impl const &)=delete
event_impl(time_point when_, DeducedHandler &&h)
event_impl(event_impl const &)=delete
void operator()() const override
queue_type & operator=(queue_type const &)=delete
iterator erase(iterator iter)
queue_type(queue_type const &)=delete
typename by_when_set::iterator iterator
boost::container::pmr::monotonic_buffer_resource * alloc_
typename boost::intrusive::make_multiset< event, boost::intrusive::constant_time_size< false > >::type by_when_set
by_when_set::iterator emplace(time_point when, Handler &&h)
Simulated discrete-event scheduler.
cancel_token in(duration const &delay, Function &&f)
Schedule an event after a specified duration passes.
clock_type & clock() const
Return the clock.
bool step()
Run the scheduler until no events remain.
time_point now() const
Return the current network time.
bool step_for(std::chrono::duration< Period, Rep > const &amount)
Run the scheduler until time has elapsed.
typename clock_type::duration duration
bool step_while(Function &&func)
Run the scheduler while a condition is true.
boost::intrusive::set_base_hook< boost::intrusive::link_mode< boost::intrusive::normal_link > > by_when_hook
typename clock_type::time_point time_point
bool step_one()
Run the scheduler for up to one event.
Scheduler & operator=(Scheduler const &)=delete
boost::container::pmr::monotonic_buffer_resource alloc_
void cancel(cancel_token const &token)
Cancel a timer.
cancel_token at(time_point const &when, Function &&f)
Schedule an event at a specific time.
Scheduler(Scheduler const &)=delete
bool step_until(time_point const &until)
Run the scheduler until the specified time.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
constexpr auto kilobytes(T value) noexcept
cancel_token(typename queue_type::iterator iter)
cancel_token & operator=(cancel_token const &)=default
queue_type::iterator iter_
cancel_token(cancel_token const &)=default
event & operator=(event const &)=delete
virtual void operator()() const =0
bool operator<(event const &other) const
event(event const &)=delete