20 #ifndef RIPPLE_TEST_CSF_SCHEDULER_H_INCLUDED
21 #define RIPPLE_TEST_CSF_SCHEDULER_H_INCLUDED
23 #include <ripple/basics/ByteUtilities.h>
24 #include <ripple/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>>;
68 virtual ~event() =
default;
85 template <
class Handler>
96 template <
class DeducedHandler>
98 :
event(when_),
h_(
std::forward<DeducedHandler>(h))
112 using by_when_set =
typename boost::intrusive::make_multiset<
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();
313 template <
class Handler>
316 typename by_when_set::iterator
319 auto const p =
alloc_->allocate(
sizeof(event_type));
320 auto& e = *
new (p) event_type(when, std::forward<Handler>(h));
321 return by_when_.insert(e);
328 auto next = by_when_.erase(iter);
330 alloc_->deallocate(&e,
sizeof(e));
370 template <
class Function>
374 return queue_.emplace(when, std::forward<Function>(f));
377 template <
class Function>
381 return at(clock_.now() + delay, std::forward<Function>(f));
413 template <
class Function>
433 if (iter->when > until)
442 }
while (iter !=
queue_.
end() && iter->when <= until);
447 template <
class Period,
class Rep>
queue_type(queue_type const &)=delete
by_when_set::iterator emplace(time_point when, Handler &&h)
event(event const &)=delete
void cancel(cancel_token const &token)
Cancel a timer.
event & operator=(event const &)=delete
bool step_while(Function &&func)
Run the scheduler while a condition is true.
clock_type & clock() const
Return the clock.
Simulated discrete-event scheduler.
constexpr auto kilobytes(T value) noexcept
void set(time_point const &when)
Set the current time of the manual clock.
typename clock_type::time_point time_point
typename by_when_set::iterator iterator
queue_type & operator=(queue_type const &)=delete
queue_type::iterator iter_
event_impl(time_point when_, DeducedHandler &&h)
bool step_one()
Run the scheduler for up to one event.
boost::container::pmr::monotonic_buffer_resource alloc_
cancel_token in(duration const &delay, Function &&f)
Schedule an event after a specified duration passes.
iterator erase(iterator iter)
typename clock_type::duration duration
bool operator<(event const &other) const
boost::intrusive::set_base_hook< boost::intrusive::link_mode< boost::intrusive::normal_link > > by_when_hook
cancel_token(typename queue_type::iterator iter)
event_impl & operator=(event_impl const &)=delete
void operator()() const override
bool step_until(time_point const &until)
Run the scheduler until the specified time.
time_point now() const override
Returns the current time.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
cancel_token at(time_point const &when, Function &&f)
Schedule an event at a specific time.
bool step()
Run the scheduler until no events remain.
virtual void operator()() const =0
typename boost::intrusive::make_multiset< event, boost::intrusive::constant_time_size< false > >::type by_when_set
boost::container::pmr::monotonic_buffer_resource * alloc_
Scheduler & operator=(Scheduler const &)=delete
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 std::chrono::steady_clock ::time_point time_point
typename std::chrono::steady_clock ::duration duration
event_impl(event_impl const &)=delete