2 #include <msp/core/raii.h>
18 for(vector<SlotProxy>::iterator i=slots.begin(); i!=slots.end(); ++i)
22 Timer::Slot &Timer::add(const TimeDelta &td)
24 Slot *s = new Slot(td);
27 push_heap(slots.begin(), slots.end());
33 Timer::Slot &Timer::add(const TimeStamp &ts)
35 Slot *s = new Slot(ts);
38 push_heap(slots.begin(), slots.end());
44 void Timer::cancel(Slot &slot)
47 for(vector<SlotProxy>::iterator i=slots.begin(); i!=slots.end(); ++i)
52 make_heap(slots.begin(), slots.end());
57 void Timer::tick(bool block)
68 next = slots.begin()->slot;
69 stamp = next->get_timeout();
76 SetFlag setf(blocking);
83 // The slots may have changed while waiting so check again
90 pop_heap(slots.begin(), slots.end());
96 if(next->signal_timeout.emit() && next->increment())
99 slots.push_back(next);
100 push_heap(slots.begin(), slots.end());
112 TimeStamp Timer::get_next_timeout() const
116 return slots.begin()->slot->get_timeout();
120 Timer::Slot::Slot(const TimeDelta &td):
122 timeout(now()+interval)
125 Timer::Slot::Slot(const TimeStamp &ts):
129 bool Timer::Slot::increment()
138 Timer::SlotProxy::SlotProxy(Slot *s):
142 bool Timer::SlotProxy::operator<(const SlotProxy &sp) const
144 return slot->get_timeout()>sp.slot->get_timeout();