20 #ifndef RIPPLE_TEST_CSF_SCHEDULER_H_INCLUDED
21 #define RIPPLE_TEST_CSF_SCHEDULER_H_INCLUDED
23 #include <ripple/basics/qalloc.h>
24 #include <ripple/beast/clock/manual_clock.h>
25 #include <boost/intrusive/set.hpp>
55 boost::intrusive::link_mode<boost::intrusive::normal_link>>;
65 virtual ~event() =
default;
82 template <
class Handler>
93 template <
class DeducedHandler>
96 ,
h_(
std::forward<DeducedHandler>(h))
110 using by_when_set =
typename boost::intrusive::make_multiset<
112 boost::intrusive::constant_time_size<false>>::type;
137 template <
class Handler>
138 typename by_when_set::iterator
184 template <
class Function>
196 template <
class Function>
247 template <
class Function>
272 template <
class Period,
class Rep>
285 for (
auto iter = by_when_.begin(); iter != by_when_.end();)
297 return by_when_.empty();
303 return by_when_.begin();
309 return by_when_.end();
313 template <
class Handler>
316 typename by_when_set::iterator
320 auto& e = *
new (p) event_type(
321 when, std::forward<Handler>(h));
322 return by_when_.insert(e);
329 auto next = by_when_.erase(iter);
377 template <
class Function>
381 return queue_.emplace(when, std::forward<Function>(f));
384 template <
class Function>
388 return at(clock_.now() + delay, std::forward<Function>(f));
420 template <
class Function>
440 if (iter->when > until)
449 }
while (iter !=
queue_.
end() && iter->when <= until);
454 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.
qalloc const & alloc() const
Return the allocator.
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.
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.
void dealloc(U *p, std::size_t n)
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
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