xref: /trunk/main/vos/source/timer.cxx (revision 4c77d9855a97d670c1bf20bf0bbd0aa291258a3a)
1e8c8fa4bSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3e8c8fa4bSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4e8c8fa4bSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5e8c8fa4bSAndrew Rist  * distributed with this work for additional information
6e8c8fa4bSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7e8c8fa4bSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8e8c8fa4bSAndrew Rist  * "License"); you may not use this file except in compliance
9e8c8fa4bSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11e8c8fa4bSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13e8c8fa4bSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14e8c8fa4bSAndrew Rist  * software distributed under the License is distributed on an
15e8c8fa4bSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16e8c8fa4bSAndrew Rist  * KIND, either express or implied.  See the License for the
17e8c8fa4bSAndrew Rist  * specific language governing permissions and limitations
18e8c8fa4bSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20e8c8fa4bSAndrew Rist  *************************************************************/
21e8c8fa4bSAndrew Rist 
22cdf0e10cSrcweir #include <osl/time.h>
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include <vos/timer.hxx>
25cdf0e10cSrcweir #include <vos/diagnose.hxx>
26cdf0e10cSrcweir #include <vos/ref.hxx>
27cdf0e10cSrcweir #include <vos/thread.hxx>
28cdf0e10cSrcweir #include <vos/conditn.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir 
31cdf0e10cSrcweir // Timer manager
32cdf0e10cSrcweir class OTimerManagerCleanup;
33cdf0e10cSrcweir 
34cdf0e10cSrcweir class vos::OTimerManager : public vos::OThread
35cdf0e10cSrcweir {
36cdf0e10cSrcweir 
37cdf0e10cSrcweir public:
38cdf0e10cSrcweir 
39*4c77d985Smseidel     //
40cdf0e10cSrcweir     OTimerManager();
41cdf0e10cSrcweir 
42*4c77d985Smseidel     //
43cdf0e10cSrcweir     ~OTimerManager();
44cdf0e10cSrcweir 
45*4c77d985Smseidel     // register timer
46cdf0e10cSrcweir     sal_Bool SAL_CALL registerTimer(vos::OTimer* pTimer);
47cdf0e10cSrcweir 
48*4c77d985Smseidel     // unregister timer
49cdf0e10cSrcweir     sal_Bool SAL_CALL unregisterTimer(vos::OTimer* pTimer);
50cdf0e10cSrcweir 
51*4c77d985Smseidel     // lookup timer
52cdf0e10cSrcweir     sal_Bool SAL_CALL lookupTimer(const vos::OTimer* pTimer);
53cdf0e10cSrcweir 
54*4c77d985Smseidel     // retrieves the "Singleton" TimerManager Instance
55cdf0e10cSrcweir     static OTimerManager* SAL_CALL getTimerManager();
56cdf0e10cSrcweir 
57cdf0e10cSrcweir 
58cdf0e10cSrcweir protected:
59cdf0e10cSrcweir 
60*4c77d985Smseidel     // worker-function of thread
61cdf0e10cSrcweir     virtual void SAL_CALL run();
62cdf0e10cSrcweir 
63cdf0e10cSrcweir     // Checking and triggering of a timer event
64cdf0e10cSrcweir     void SAL_CALL checkForTimeout();
65cdf0e10cSrcweir 
66cdf0e10cSrcweir     // cleanup Method
67cdf0e10cSrcweir     virtual void SAL_CALL onTerminated();
68cdf0e10cSrcweir 
69cdf0e10cSrcweir     // sorted-queue data
70cdf0e10cSrcweir     vos::OTimer*        m_pHead;
71cdf0e10cSrcweir     // List Protection
72cdf0e10cSrcweir     vos::OMutex     m_Lock;
73cdf0e10cSrcweir     // Signal the insertion of a timer
74cdf0e10cSrcweir     vos::OCondition m_notEmpty;
75cdf0e10cSrcweir 
76cdf0e10cSrcweir     // Synchronize access to OTimerManager
77cdf0e10cSrcweir     static vos::OMutex m_Access;
78cdf0e10cSrcweir 
79cdf0e10cSrcweir     // "Singleton Pattern"
80cdf0e10cSrcweir     static vos::OTimerManager* m_pManager;
81cdf0e10cSrcweir 
82cdf0e10cSrcweir     friend class OTimerManagerCleanup;
83cdf0e10cSrcweir 
84cdf0e10cSrcweir };
85cdf0e10cSrcweir 
86cdf0e10cSrcweir using namespace vos;
87cdf0e10cSrcweir 
88cdf0e10cSrcweir // Timer class
89cdf0e10cSrcweir VOS_IMPLEMENT_CLASSINFO(VOS_CLASSNAME(OTimer, vos),
90cdf0e10cSrcweir                         VOS_NAMESPACE(OTimer, vos),
91cdf0e10cSrcweir                         VOS_NAMESPACE(OObject, vos), 0);
92cdf0e10cSrcweir 
OTimer()93cdf0e10cSrcweir OTimer::OTimer()
94cdf0e10cSrcweir {
95cdf0e10cSrcweir     m_TimeOut     = 0;
96cdf0e10cSrcweir     m_Expired     = 0;
97cdf0e10cSrcweir     m_RepeatDelta = 0;
98cdf0e10cSrcweir     m_pNext       = 0;
99cdf0e10cSrcweir }
100cdf0e10cSrcweir 
OTimer(const TTimeValue & Time)101cdf0e10cSrcweir OTimer::OTimer(const TTimeValue& Time)
102cdf0e10cSrcweir {
103cdf0e10cSrcweir     m_TimeOut     = Time;
104cdf0e10cSrcweir     m_RepeatDelta = 0;
105cdf0e10cSrcweir     m_Expired     = 0;
106cdf0e10cSrcweir     m_pNext       = 0;
107cdf0e10cSrcweir 
108cdf0e10cSrcweir     m_TimeOut.normalize();
109cdf0e10cSrcweir }
110cdf0e10cSrcweir 
OTimer(const TTimeValue & Time,const TTimeValue & Repeat)111cdf0e10cSrcweir OTimer::OTimer(const TTimeValue& Time, const TTimeValue& Repeat)
112cdf0e10cSrcweir {
113cdf0e10cSrcweir     m_TimeOut     = Time;
114cdf0e10cSrcweir     m_RepeatDelta = Repeat;
115cdf0e10cSrcweir     m_Expired     = 0;
116cdf0e10cSrcweir     m_pNext       = 0;
117cdf0e10cSrcweir 
118cdf0e10cSrcweir     m_TimeOut.normalize();
119cdf0e10cSrcweir     m_RepeatDelta.normalize();
120cdf0e10cSrcweir }
121cdf0e10cSrcweir 
~OTimer()122cdf0e10cSrcweir OTimer::~OTimer()
123cdf0e10cSrcweir {
124cdf0e10cSrcweir     stop();
125cdf0e10cSrcweir }
126cdf0e10cSrcweir 
start()127cdf0e10cSrcweir void OTimer::start()
128cdf0e10cSrcweir {
129cdf0e10cSrcweir     if (! isTicking())
130cdf0e10cSrcweir     {
131cdf0e10cSrcweir         if (! m_TimeOut.isEmpty())
132cdf0e10cSrcweir             setRemainingTime(m_TimeOut);
133cdf0e10cSrcweir 
134cdf0e10cSrcweir         OTimerManager *pManager = OTimerManager::getTimerManager();
135cdf0e10cSrcweir 
136cdf0e10cSrcweir         VOS_ASSERT(pManager);
137cdf0e10cSrcweir 
138cdf0e10cSrcweir         if ( pManager != 0 )
139cdf0e10cSrcweir         {
140cdf0e10cSrcweir             pManager->registerTimer(this);
141cdf0e10cSrcweir         }
142cdf0e10cSrcweir     }
143cdf0e10cSrcweir }
144cdf0e10cSrcweir 
stop()145cdf0e10cSrcweir void OTimer::stop()
146cdf0e10cSrcweir {
147cdf0e10cSrcweir     OTimerManager *pManager = OTimerManager::getTimerManager();
148cdf0e10cSrcweir 
149cdf0e10cSrcweir     VOS_ASSERT(pManager);
150cdf0e10cSrcweir 
151cdf0e10cSrcweir     if ( pManager != 0 )
152cdf0e10cSrcweir     {
153cdf0e10cSrcweir         pManager->unregisterTimer(this);
154cdf0e10cSrcweir     }
155cdf0e10cSrcweir }
156cdf0e10cSrcweir 
isTicking() const157cdf0e10cSrcweir sal_Bool OTimer::isTicking() const
158cdf0e10cSrcweir {
159cdf0e10cSrcweir     OTimerManager *pManager = OTimerManager::getTimerManager();
160cdf0e10cSrcweir 
161cdf0e10cSrcweir     VOS_ASSERT(pManager);
162cdf0e10cSrcweir 
163cdf0e10cSrcweir     if (pManager)
164cdf0e10cSrcweir         return pManager->lookupTimer(this);
165cdf0e10cSrcweir     else
166cdf0e10cSrcweir         return sal_False;
167cdf0e10cSrcweir 
168cdf0e10cSrcweir }
169cdf0e10cSrcweir 
isExpired() const170cdf0e10cSrcweir sal_Bool OTimer::isExpired() const
171cdf0e10cSrcweir {
172cdf0e10cSrcweir     TTimeValue Now;
173cdf0e10cSrcweir 
174cdf0e10cSrcweir     osl_getSystemTime(&Now);
175cdf0e10cSrcweir 
176cdf0e10cSrcweir     return !(Now < m_Expired);
177cdf0e10cSrcweir }
178cdf0e10cSrcweir 
expiresBefore(const OTimer * pTimer) const179cdf0e10cSrcweir sal_Bool OTimer::expiresBefore(const OTimer* pTimer) const
180cdf0e10cSrcweir {
181cdf0e10cSrcweir     VOS_ASSERT(pTimer);
182cdf0e10cSrcweir 
183cdf0e10cSrcweir     if ( pTimer != 0 )
184cdf0e10cSrcweir     {
185cdf0e10cSrcweir         return m_Expired < pTimer->m_Expired;
186cdf0e10cSrcweir     }
187cdf0e10cSrcweir     else
188cdf0e10cSrcweir     {
189cdf0e10cSrcweir         return sal_False;
190cdf0e10cSrcweir     }
191cdf0e10cSrcweir }
192cdf0e10cSrcweir 
setAbsoluteTime(const TTimeValue & Time)193cdf0e10cSrcweir void OTimer::setAbsoluteTime(const TTimeValue& Time)
194cdf0e10cSrcweir {
195cdf0e10cSrcweir     m_TimeOut     = 0;
196cdf0e10cSrcweir     m_Expired     = Time;
197cdf0e10cSrcweir     m_RepeatDelta = 0;
198cdf0e10cSrcweir 
199cdf0e10cSrcweir     m_Expired.normalize();
200cdf0e10cSrcweir }
201cdf0e10cSrcweir 
setRemainingTime(const TTimeValue & Remaining)202cdf0e10cSrcweir void OTimer::setRemainingTime(const TTimeValue& Remaining)
203cdf0e10cSrcweir {
204cdf0e10cSrcweir     osl_getSystemTime(&m_Expired);
205cdf0e10cSrcweir 
206cdf0e10cSrcweir     m_Expired.addTime(Remaining);
207cdf0e10cSrcweir }
208cdf0e10cSrcweir 
setRemainingTime(const TTimeValue & Remaining,const TTimeValue & Repeat)209cdf0e10cSrcweir void OTimer::setRemainingTime(const TTimeValue& Remaining, const TTimeValue& Repeat)
210cdf0e10cSrcweir {
211cdf0e10cSrcweir     osl_getSystemTime(&m_Expired);
212cdf0e10cSrcweir 
213cdf0e10cSrcweir     m_Expired.addTime(Remaining);
214cdf0e10cSrcweir 
215cdf0e10cSrcweir     m_RepeatDelta = Repeat;
216cdf0e10cSrcweir }
217cdf0e10cSrcweir 
addTime(const TTimeValue & Delta)218cdf0e10cSrcweir void OTimer::addTime(const TTimeValue& Delta)
219cdf0e10cSrcweir {
220cdf0e10cSrcweir     m_Expired.addTime(Delta);
221cdf0e10cSrcweir }
222cdf0e10cSrcweir 
getRemainingTime() const223cdf0e10cSrcweir TTimeValue OTimer::getRemainingTime() const
224cdf0e10cSrcweir {
225cdf0e10cSrcweir     TTimeValue Now;
226cdf0e10cSrcweir 
227cdf0e10cSrcweir     osl_getSystemTime(&Now);
228cdf0e10cSrcweir 
229cdf0e10cSrcweir     sal_Int32 secs = m_Expired.Seconds - Now.Seconds;
230cdf0e10cSrcweir 
231cdf0e10cSrcweir     if (secs < 0)
232cdf0e10cSrcweir         return TTimeValue(0, 0);
233cdf0e10cSrcweir 
234cdf0e10cSrcweir     sal_Int32 nsecs = m_Expired.Nanosec - Now.Nanosec;
235cdf0e10cSrcweir 
236cdf0e10cSrcweir     if (nsecs < 0)
237cdf0e10cSrcweir     {
238cdf0e10cSrcweir         if (secs > 0)
239cdf0e10cSrcweir         {
240cdf0e10cSrcweir             secs  -= 1;
241cdf0e10cSrcweir             nsecs += 1000000000;
242cdf0e10cSrcweir         }
243cdf0e10cSrcweir         else
244cdf0e10cSrcweir             return TTimeValue(0, 0);
245cdf0e10cSrcweir     }
246cdf0e10cSrcweir 
247cdf0e10cSrcweir     return TTimeValue(secs, nsecs);
248cdf0e10cSrcweir }
249cdf0e10cSrcweir 
250cdf0e10cSrcweir 
251cdf0e10cSrcweir // Timer manager
252cdf0e10cSrcweir OMutex vos::OTimerManager::m_Access;
253cdf0e10cSrcweir OTimerManager* vos::OTimerManager::m_pManager=0;
254cdf0e10cSrcweir 
OTimerManager()255cdf0e10cSrcweir OTimerManager::OTimerManager()
256cdf0e10cSrcweir {
257cdf0e10cSrcweir     OGuard Guard(&m_Access);
258cdf0e10cSrcweir 
259cdf0e10cSrcweir     VOS_ASSERT(m_pManager == 0);
260cdf0e10cSrcweir 
261cdf0e10cSrcweir     m_pManager = this;
262cdf0e10cSrcweir 
263cdf0e10cSrcweir     m_pHead= 0;
264cdf0e10cSrcweir 
265cdf0e10cSrcweir     m_notEmpty.reset();
266cdf0e10cSrcweir 
267cdf0e10cSrcweir     // start thread
268cdf0e10cSrcweir     create();
269cdf0e10cSrcweir }
270cdf0e10cSrcweir 
~OTimerManager()271cdf0e10cSrcweir OTimerManager::~OTimerManager()
272cdf0e10cSrcweir {
273cdf0e10cSrcweir     OGuard Guard(&m_Access);
274cdf0e10cSrcweir 
275cdf0e10cSrcweir     if ( m_pManager == this )
276cdf0e10cSrcweir         m_pManager = 0;
277cdf0e10cSrcweir }
278cdf0e10cSrcweir 
onTerminated()279cdf0e10cSrcweir void OTimerManager::onTerminated()
280cdf0e10cSrcweir {
281cdf0e10cSrcweir     delete this; // mfe: AAARRRGGGHHH!!!
282cdf0e10cSrcweir }
283cdf0e10cSrcweir 
getTimerManager()284cdf0e10cSrcweir OTimerManager* OTimerManager::getTimerManager()
285cdf0e10cSrcweir {
286cdf0e10cSrcweir     OGuard Guard(&m_Access);
287cdf0e10cSrcweir 
288cdf0e10cSrcweir     if (! m_pManager)
289cdf0e10cSrcweir         new OTimerManager;
290cdf0e10cSrcweir 
291cdf0e10cSrcweir     return (m_pManager);
292cdf0e10cSrcweir }
293cdf0e10cSrcweir 
registerTimer(OTimer * pTimer)294cdf0e10cSrcweir sal_Bool OTimerManager::registerTimer(OTimer* pTimer)
295cdf0e10cSrcweir {
296cdf0e10cSrcweir     VOS_ASSERT(pTimer);
297cdf0e10cSrcweir 
298cdf0e10cSrcweir     if ( pTimer == 0 )
299cdf0e10cSrcweir     {
300cdf0e10cSrcweir         return sal_False;
301cdf0e10cSrcweir     }
302cdf0e10cSrcweir 
303cdf0e10cSrcweir     OGuard Guard(&m_Lock);
304cdf0e10cSrcweir 
305cdf0e10cSrcweir     // try to find one with equal or lower remaining time.
306cdf0e10cSrcweir     OTimer** ppIter = &m_pHead;
307cdf0e10cSrcweir 
308cdf0e10cSrcweir     while (*ppIter)
309cdf0e10cSrcweir     {
310cdf0e10cSrcweir         if (pTimer->expiresBefore(*ppIter))
311cdf0e10cSrcweir         {
312cdf0e10cSrcweir             // next element has higher remaining time,
313cdf0e10cSrcweir             // => insert new timer before
314cdf0e10cSrcweir             break;
315cdf0e10cSrcweir         }
316cdf0e10cSrcweir         ppIter= &((*ppIter)->m_pNext);
317cdf0e10cSrcweir     }
318cdf0e10cSrcweir 
319cdf0e10cSrcweir     // next element has higher remaining time,
320cdf0e10cSrcweir     // => insert new timer before
321cdf0e10cSrcweir     pTimer->m_pNext= *ppIter;
322cdf0e10cSrcweir     *ppIter = pTimer;
323cdf0e10cSrcweir 
324cdf0e10cSrcweir 
325cdf0e10cSrcweir     if (pTimer == m_pHead)
326cdf0e10cSrcweir     {
327cdf0e10cSrcweir         // it was inserted as new head
328cdf0e10cSrcweir         // signal it to TimerManager Thread
329cdf0e10cSrcweir         m_notEmpty.set();
330cdf0e10cSrcweir     }
331cdf0e10cSrcweir 
332cdf0e10cSrcweir     return sal_True;
333cdf0e10cSrcweir }
334cdf0e10cSrcweir 
unregisterTimer(OTimer * pTimer)335cdf0e10cSrcweir sal_Bool OTimerManager::unregisterTimer(OTimer* pTimer)
336cdf0e10cSrcweir {
337cdf0e10cSrcweir     VOS_ASSERT(pTimer);
338cdf0e10cSrcweir 
339cdf0e10cSrcweir     if ( pTimer == 0 )
340cdf0e10cSrcweir     {
341cdf0e10cSrcweir         return sal_False;
342cdf0e10cSrcweir     }
343cdf0e10cSrcweir 
344cdf0e10cSrcweir     // lock access
345cdf0e10cSrcweir     OGuard Guard(&m_Lock);
346cdf0e10cSrcweir 
347cdf0e10cSrcweir     OTimer** ppIter = &m_pHead;
348cdf0e10cSrcweir 
349cdf0e10cSrcweir     while (*ppIter)
350cdf0e10cSrcweir     {
351cdf0e10cSrcweir         if (pTimer == (*ppIter))
352cdf0e10cSrcweir         {
353cdf0e10cSrcweir             // remove timer from list
354cdf0e10cSrcweir             *ppIter = (*ppIter)->m_pNext;
355cdf0e10cSrcweir             return sal_True;
356cdf0e10cSrcweir         }
357cdf0e10cSrcweir         ppIter= &((*ppIter)->m_pNext);
358cdf0e10cSrcweir     }
359cdf0e10cSrcweir 
360cdf0e10cSrcweir     return sal_False;
361cdf0e10cSrcweir }
362cdf0e10cSrcweir 
lookupTimer(const OTimer * pTimer)363cdf0e10cSrcweir sal_Bool OTimerManager::lookupTimer(const OTimer* pTimer)
364cdf0e10cSrcweir {
365cdf0e10cSrcweir     VOS_ASSERT(pTimer);
366cdf0e10cSrcweir 
367cdf0e10cSrcweir     if ( pTimer == 0 )
368cdf0e10cSrcweir     {
369cdf0e10cSrcweir         return sal_False;
370cdf0e10cSrcweir     }
371cdf0e10cSrcweir 
372cdf0e10cSrcweir     // lock access
373cdf0e10cSrcweir     OGuard Guard(&m_Lock);
374cdf0e10cSrcweir 
375cdf0e10cSrcweir     // check the list
376cdf0e10cSrcweir     for (OTimer* pIter = m_pHead; pIter != 0; pIter= pIter->m_pNext)
377cdf0e10cSrcweir     {
378cdf0e10cSrcweir         if (pIter == pTimer)
379cdf0e10cSrcweir         {
380cdf0e10cSrcweir             return sal_True;
381cdf0e10cSrcweir         }
382cdf0e10cSrcweir     }
383cdf0e10cSrcweir 
384cdf0e10cSrcweir     return sal_False;
385cdf0e10cSrcweir }
386cdf0e10cSrcweir 
checkForTimeout()387cdf0e10cSrcweir void OTimerManager::checkForTimeout()
388cdf0e10cSrcweir {
389cdf0e10cSrcweir 
390cdf0e10cSrcweir     m_Lock.acquire();
391cdf0e10cSrcweir 
392cdf0e10cSrcweir     if ( m_pHead == 0 )
393cdf0e10cSrcweir     {
394cdf0e10cSrcweir         m_Lock.release();
395cdf0e10cSrcweir         return;
396cdf0e10cSrcweir     }
397cdf0e10cSrcweir 
398cdf0e10cSrcweir     OTimer* pTimer = m_pHead;
399cdf0e10cSrcweir 
400cdf0e10cSrcweir     if (pTimer->isExpired())
401cdf0e10cSrcweir     {
402cdf0e10cSrcweir         // remove expired timer
403cdf0e10cSrcweir         m_pHead = pTimer->m_pNext;
404cdf0e10cSrcweir 
405cdf0e10cSrcweir         pTimer->acquire();
406cdf0e10cSrcweir 
407cdf0e10cSrcweir         m_Lock.release();
408cdf0e10cSrcweir 
409cdf0e10cSrcweir         pTimer->onShot();
410cdf0e10cSrcweir 
411cdf0e10cSrcweir         // restart timer if specified
412cdf0e10cSrcweir         if ( ! pTimer->m_RepeatDelta.isEmpty() )
413cdf0e10cSrcweir         {
414cdf0e10cSrcweir             TTimeValue Now;
415cdf0e10cSrcweir 
416cdf0e10cSrcweir             osl_getSystemTime(&Now);
417cdf0e10cSrcweir 
418cdf0e10cSrcweir             Now.Seconds += pTimer->m_RepeatDelta.Seconds;
419cdf0e10cSrcweir             Now.Nanosec += pTimer->m_RepeatDelta.Nanosec;
420cdf0e10cSrcweir 
421cdf0e10cSrcweir             pTimer->m_Expired = Now;
422cdf0e10cSrcweir 
423cdf0e10cSrcweir             registerTimer(pTimer);
424cdf0e10cSrcweir         }
425cdf0e10cSrcweir         pTimer->release();
426cdf0e10cSrcweir     }
427cdf0e10cSrcweir     else
428cdf0e10cSrcweir     {
429cdf0e10cSrcweir         m_Lock.release();
430cdf0e10cSrcweir     }
431cdf0e10cSrcweir 
432cdf0e10cSrcweir 
433cdf0e10cSrcweir     return;
434cdf0e10cSrcweir }
435cdf0e10cSrcweir 
run()436cdf0e10cSrcweir void OTimerManager::run()
437cdf0e10cSrcweir {
438cdf0e10cSrcweir     setPriority(TPriority_BelowNormal);
439cdf0e10cSrcweir 
440cdf0e10cSrcweir     while (schedule())
441cdf0e10cSrcweir     {
442cdf0e10cSrcweir         TTimeValue      delay;
443cdf0e10cSrcweir         TTimeValue*     pDelay=0;
444cdf0e10cSrcweir 
445cdf0e10cSrcweir 
446cdf0e10cSrcweir         m_Lock.acquire();
447cdf0e10cSrcweir 
448cdf0e10cSrcweir         if (m_pHead != 0)
449cdf0e10cSrcweir         {
450cdf0e10cSrcweir             delay = m_pHead->getRemainingTime();
451cdf0e10cSrcweir             pDelay=&delay;
452cdf0e10cSrcweir         }
453cdf0e10cSrcweir         else
454cdf0e10cSrcweir         {
455cdf0e10cSrcweir             pDelay=0;
456cdf0e10cSrcweir         }
457cdf0e10cSrcweir 
458cdf0e10cSrcweir 
459cdf0e10cSrcweir         m_notEmpty.reset();
460cdf0e10cSrcweir 
461cdf0e10cSrcweir         m_Lock.release();
462cdf0e10cSrcweir 
463cdf0e10cSrcweir 
464cdf0e10cSrcweir         m_notEmpty.wait(pDelay);
465cdf0e10cSrcweir 
466cdf0e10cSrcweir         checkForTimeout();
467cdf0e10cSrcweir     }
468cdf0e10cSrcweir 
469cdf0e10cSrcweir }
470cdf0e10cSrcweir 
471cdf0e10cSrcweir // Timer manager cleanup
472cdf0e10cSrcweir 
473cdf0e10cSrcweir // jbu:
474cdf0e10cSrcweir // The timer manager cleanup has been removed (no thread is killed anymore).
475cdf0e10cSrcweir // So the thread leaks.
476cdf0e10cSrcweir // This will result in a GPF in case the vos-library gets unloaded before
477cdf0e10cSrcweir // process termination.
478cdf0e10cSrcweir // -> TODO : rewrite this file, so that the timerManager thread gets destroyed,
479cdf0e10cSrcweir //           when there are no timers anymore !
480*4c77d985Smseidel 
481*4c77d985Smseidel /* vim: set noet sw=4 ts=4: */
482