3 This file is part of libmspcore
4 Copyright © 2006 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
18 for(set<SlotProxy>::iterator i=slots.begin(); i!=slots.end(); ++i)
22 Timer::Slot &Timer::add(const TimeDelta &td)
32 Timer::Slot &Timer::add(const TimeStamp &ts)
43 void Timer::cancel(Slot &slot)
46 if(slots.erase(&slot))
50 void Timer::tick(bool block)
63 next=slots.begin()->slot;
66 const TimeStamp &stamp=next->get_timeout();
67 const TimeStamp t=now();
68 if(stamp<=t || (block && sem.wait(stamp-t)==1))
70 slots.erase(slots.begin());
71 if(next->signal_timeout.emit() && next->increment())
78 TimeStamp Timer::get_next_timeout() const
82 return slots.begin()->slot->get_timeout();
86 Timer::Slot::Slot(const TimeDelta &td):
88 timeout(now()+interval)
91 Timer::Slot::Slot(const TimeStamp &ts):
95 bool Timer::Slot::increment()
104 Timer::SlotProxy::SlotProxy(Slot *s):
108 bool Timer::SlotProxy::operator<(const SlotProxy &sp) const
110 return slot->get_timeout()<sp.slot->get_timeout();