3 This file is part of libmspcore
4 Copyright © 2006, 2009 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
19 for(vector<SlotProxy>::iterator i=slots.begin(); i!=slots.end(); ++i)
23 Timer::Slot &Timer::add(const TimeDelta &td)
25 Slot *s = new Slot(td);
28 push_heap(slots.begin(), slots.end());
34 Timer::Slot &Timer::add(const TimeStamp &ts)
36 Slot *s = new Slot(ts);
40 push_heap(slots.begin(), slots.end());
46 void Timer::cancel(Slot &slot)
49 for(vector<SlotProxy>::iterator i=slots.begin(); i!=slots.end(); ++i)
54 make_heap(slots.begin(), slots.end());
59 void Timer::tick(bool block)
74 next = slots.begin()->slot;
75 const TimeStamp &stamp = next->get_timeout();
76 const TimeStamp t = now();
85 pop_heap(slots.begin(), slots.end());
91 if(next->signal_timeout.emit() && next->increment())
94 slots.push_back(next);
95 push_heap(slots.begin(), slots.end());
107 TimeStamp Timer::get_next_timeout() const
111 return slots.begin()->slot->get_timeout();
115 Timer::Slot::Slot(const TimeDelta &td):
117 timeout(now()+interval)
120 Timer::Slot::Slot(const TimeStamp &ts):
124 bool Timer::Slot::increment()
133 Timer::SlotProxy::SlotProxy(Slot *s):
137 bool Timer::SlotProxy::operator<(const SlotProxy &sp) const
139 return slot->get_timeout()>sp.slot->get_timeout();