2 This file is part of libmspframework
3 Copyright © 2006 Mikko Rasa, Mikkosoft Productions
4 Distributed under the LGPL
14 Timer::Timer(const Time::TimeDelta &d):
18 MutexLock l(set_mutex);
25 MutexLock l(set_mutex);
30 Timer::ThreadProxy Timer::thread;
31 Mutex Timer::set_mutex;
32 set<Timer *> Timer::timers;
34 Timer::Thread::Thread():
41 Notifies the thread that a change in the timers occurred.
43 void Timer::Thread::nudge()
49 Tells the thread to finish and terminate gracefully. This function will return
50 after the thread has terminated.
52 void Timer::Thread::finish()
63 void Timer::Thread::main()
70 for(set<Timer *>::iterator i=timers.begin(); i!=timers.end(); ++i)
72 const TimeStamp &ts=(*i)->get_timeout();
73 if(ts<next_ts || !next)
83 const TimeStamp t=now();
84 if(next_ts<=t || sem.wait(next_ts-t)==1)
86 if(next->signal_timeout.emit())
87 next->timeout+=next->interval;
98 Creates the thread if it doesn't exist, otherwise nudges it.
100 void Timer::ThreadProxy::nudge()
108 Timer::ThreadProxy::~ThreadProxy()