2 This file is part of libmspcore
3 Copyright © 2006 Mikko Rasa, Mikkosoft Productions
4 Distributed under the LGPL
17 for(set<SlotProxy>::iterator i=slots.begin(); i!=slots.end(); ++i)
21 Timer::Slot &Timer::add(const TimeDelta &td)
31 Timer::Slot &Timer::add(const TimeStamp &ts)
42 void Timer::cancel(Slot &slot)
45 if(slots.erase(&slot))
49 void Timer::tick(bool block)
62 next=slots.begin()->slot;
65 const TimeStamp &stamp=next->get_timeout();
66 const TimeStamp t=now();
67 if(stamp<=t || (block && sem.wait(stamp-t)==1))
69 slots.erase(slots.begin());
70 if(next->signal_timeout.emit() && next->increment())
77 TimeStamp Timer::get_next_timeout() const
81 return slots.begin()->slot->get_timeout();
85 Timer::Slot::Slot(const TimeDelta &td):
87 timeout(now()+interval)
90 Timer::Slot::Slot(const TimeStamp &ts):
94 bool Timer::Slot::increment()
103 Timer::SlotProxy::SlotProxy(Slot *s):
107 bool Timer::SlotProxy::operator<(const SlotProxy &sp) const
109 return slot->get_timeout()<sp.slot->get_timeout();