2 This file is part of libmspframework
3 Copyright © 2006 Mikko Rasa, Mikkosoft Productions
4 Distributed under the LGPL
15 Timer::Timer(const Time::TimeDelta &d):
19 MutexLock l(set_mutex);
26 MutexLock l(set_mutex);
31 Timer::ThreadProxy Timer::thread;
32 Mutex Timer::set_mutex;
33 set<Timer *> Timer::timers;
35 Timer::Thread::Thread():
42 Notifies the thread that a change in the timers occurred.
44 void Timer::Thread::nudge()
50 Tells the thread to finish and terminate gracefully. This function will return
51 after the thread has terminated.
53 void Timer::Thread::finish()
64 void Timer::Thread::main()
71 for(set<Timer *>::iterator i=timers.begin(); i!=timers.end(); ++i)
73 const TimeStamp &ts=(*i)->get_timeout();
74 if(ts<next_ts || !next)
84 const TimeStamp t=now();
85 if(next_ts<=t || sem.wait(next_ts-t)==1)
87 if(next->signal_timeout.emit())
88 next->timeout+=next->interval;
99 Creates the thread if it doesn't exist, otherwise nudges it.
101 void Timer::ThreadProxy::nudge()
109 Timer::ThreadProxy::~ThreadProxy()