From c78c3ce853230ef39db6fc1ed85702430b9e4c56 Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Tue, 25 Jun 2002 15:11:52 +0000 Subject: [PATCH] clean up state transitions --- src/libCom/timer/timer.cpp | 9 ++++++--- src/libCom/timer/timerQueue.cpp | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/libCom/timer/timer.cpp b/src/libCom/timer/timer.cpp index b0db4a169..8159ee643 100644 --- a/src/libCom/timer/timer.cpp +++ b/src/libCom/timer/timer.cpp @@ -148,7 +148,6 @@ void timer::privateCancel ( epicsGuard < epicsMutex > & locker ) } else if ( this->curState == stateActive ) { this->queue.cancelPending = true; - this->curState = timer::stateLimbo; if ( this->queue.processThread != epicsThreadGetIdSelf() ) { // make certain timer expire() does not run after cancel () returns, // but dont require that lock is applied while calling expire() @@ -158,15 +157,19 @@ void timer::privateCancel ( epicsGuard < epicsMutex > & locker ) this->queue.pExpireTmr == this ) { this->queue.cancelBlockingEvent.wait (); } - // in case other threads are waiting - this->queue.cancelBlockingEvent.signal (); } + // in case other threads are waiting + this->queue.cancelBlockingEvent.signal (); } } } epicsTimer::expireInfo timer::getExpireInfo () const { + // taking a lock here guarantees that users will not + // see brief intervals when a timer isnt active because + // it is is canceled when start is called + epicsGuard < epicsMutex > locker ( this->queue.mutex ); if ( this->curState == statePending || this->curState == stateActive ) { return expireInfo ( true, this->exp ); } diff --git a/src/libCom/timer/timerQueue.cpp b/src/libCom/timer/timerQueue.cpp index 08dd50214..72d62f1e0 100644 --- a/src/libCom/timer/timerQueue.cpp +++ b/src/libCom/timer/timerQueue.cpp @@ -118,22 +118,25 @@ double timerQueue::process ( const epicsTime & currentTime ) // while the call back was running // if ( this->cancelPending ) { + this->pExpireTmr->curState = timer::stateLimbo; // 1) if another thread is canceling cancel() waits for this // 2) if this thread is canceling in the timer callback then // dont touch timer or notify here because the cancel might - // have occurred because they destroyed the time rin the + // have occurred because they destroyed the timer in the // callback this->cancelPending = false; this->cancelBlockingEvent.signal (); } - // restart as nec else { - this->pExpireTmr->curState = timer::stateLimbo; + // restart as nec if ( expStat.restart() ) { this->pExpireTmr->privateStart ( *pTmpNotify, currentTime + expStat.expirationDelay() ); } + else { + this->pExpireTmr->curState = timer::stateLimbo; + } } this->pExpireTmr = 0;