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