1 #include "hmbdc/Copyright.hpp" 4 #include "hmbdc/time/Time.hpp" 5 #include "hmbdc/Exception.hpp" 6 #include "hmbdc/Compile.hpp" 13 #include <boost/intrusive/set.hpp> 16 namespace hmbdc {
namespace time {
18 namespace timers_detail {
19 void noop(TimerManager&, SysTime
const&);
23 : boost::intrusive::set_base_hook<
24 boost::intrusive::link_mode<boost::intrusive::normal_link>
29 SysTime getFireAt()
const {
return fireAt_; }
32 using Callback = std::function<void (TimerManager&, SysTime const&)>;
33 Timer(Callback cb = timers_detail::noop)
37 void setCallback(Callback cb) {
41 bool operator < (
Timer const& other)
const 42 {
return fireAt_ < other.fireAt_; }
43 bool operator <= (
SysTime const& t)
const 44 {
return !(t < fireAt_); }
58 namespace timers_detail {
67 timer.fireAt_ = fireAt;
68 timers_.insert(timer);
78 auto range = timers_.equal_range(timer);
79 for (
auto it = range.first; it != range.second; ++it) {
91 using Timers = boost::intrusive::multiset<Timer>;
104 { tm.schedule(now + interval, *
this); };
108 DailyTimer(Callback callback = timers_detail::noop)
113 Duration day = Duration::seconds(86400);
114 SysTime newFireTime = getFireAt() + day;
115 while (newFireTime < now) newFireTime += day;
116 tm.schedule(newFireTime, *
this);
Definition: Timers.hpp:22
Definition: Timers.hpp:65
Definition: Timers.hpp:107
void cancel(Timer &timer)
cancel a timer previously scheduled with the TimerManager
Definition: Timers.hpp:77
Definition: Timers.hpp:120
Definition: Timers.hpp:96