From a251b89e137b1f0716b044005defdbe4149ef67f Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Wed, 27 Feb 2002 23:32:44 +0000 Subject: [PATCH] auto mutex release now requires an auto mutex --- src/libCom/misc/ipAddrToAsciiAsynchronous.cpp | 2 +- src/libCom/osi/epicsMutex.h | 19 ++++++++++--------- src/libCom/timer/timer.cpp | 8 ++++---- src/libCom/timer/timerPrivate.h | 2 +- src/libCom/timer/timerQueueActive.cpp | 2 +- 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/libCom/misc/ipAddrToAsciiAsynchronous.cpp b/src/libCom/misc/ipAddrToAsciiAsynchronous.cpp index 05272a29c..ba3a49b73 100644 --- a/src/libCom/misc/ipAddrToAsciiAsynchronous.cpp +++ b/src/libCom/misc/ipAddrToAsciiAsynchronous.cpp @@ -147,7 +147,7 @@ ipAddrToAsciiAsynchronous::~ipAddrToAsciiAsynchronous () ! this->pEngine->thread.isCurrentThread() ) { this->pEngine->cancelPending = true; { - epicsAutoMutexRelease unlocker ( ipAddrToAsciiEngine::mutex ); + epicsAutoMutexRelease unlocker ( locker ); this->pEngine->destructorBlockEvent.wait (); } if ( ! this->pEngine ) { diff --git a/src/libCom/osi/epicsMutex.h b/src/libCom/osi/epicsMutex.h index 6bad256ab..d838640ea 100644 --- a/src/libCom/osi/epicsMutex.h +++ b/src/libCom/osi/epicsMutex.h @@ -25,9 +25,9 @@ public: class noMemory {}; // exception class invalidSemaphore {}; // exception private: + epicsMutexId id; epicsMutex ( const epicsMutex & ); epicsMutex & operator = ( const epicsMutex & ); - epicsMutexId id; }; // Automatically applies and releases the mutex. @@ -37,21 +37,22 @@ public: epicsAutoMutex ( epicsMutex & ); ~epicsAutoMutex (); private: + epicsMutex & rMutex; epicsAutoMutex ( const epicsAutoMutex & ); epicsAutoMutex & operator = ( const epicsAutoMutex & ); - epicsMutex & rMutex; + friend class epicsAutoMutexRelease; }; // Automatically releases and reapplies the mutex. // This is for use in situations where C++ exceptions are possible. class epicsAutoMutexRelease { public: - epicsAutoMutexRelease ( epicsMutex & ); + epicsAutoMutexRelease ( epicsAutoMutex & ); ~epicsAutoMutexRelease (); private: - epicsAutoMutexRelease ( const epicsAutoMutex & ); + epicsAutoMutex & autoMutex; + epicsAutoMutexRelease ( const epicsAutoMutexRelease & ); epicsAutoMutexRelease & operator = ( const epicsAutoMutexRelease & ); - epicsMutex & rMutex; }; @@ -167,15 +168,15 @@ inline epicsAutoMutex :: ~epicsAutoMutex () this->rMutex.unlock (); } -inline epicsAutoMutexRelease :: epicsAutoMutexRelease ( epicsMutex & mutexIn ) : - rMutex ( mutexIn ) +inline epicsAutoMutexRelease :: epicsAutoMutexRelease ( epicsAutoMutex & autoMutexIn ) : + autoMutex ( autoMutexIn ) { - this->rMutex.unlock (); + this->autoMutex.rMutex.unlock (); } inline epicsAutoMutexRelease :: ~epicsAutoMutexRelease () { - this->rMutex.lock (); + this->autoMutex.rMutex.lock (); } #endif /*__cplusplus*/ diff --git a/src/libCom/timer/timer.cpp b/src/libCom/timer/timer.cpp index 57411808f..5b11a982f 100644 --- a/src/libCom/timer/timer.cpp +++ b/src/libCom/timer/timer.cpp @@ -68,7 +68,7 @@ void timer::start ( epicsTimerNotify & notify, double delaySeconds ) void timer::start ( epicsTimerNotify & notify, const epicsTime & expire ) { epicsAutoMutex locker ( this->queue.mutex ); - this->privateCancel (); + this->privateCancel ( locker ); this->privateStart ( notify, expire ); } @@ -127,10 +127,10 @@ void timer::privateStart ( epicsTimerNotify & notify, const epicsTime & expire ) void timer::cancel () { epicsAutoMutex locker ( this->queue.mutex ); - this->privateCancel (); + this->privateCancel ( locker ); } -void timer::privateCancel () +void timer::privateCancel ( epicsAutoMutex & locker ) { while ( true ) { if ( this->curState == statePending ) { @@ -147,7 +147,7 @@ void timer::privateCancel () // make certain timer expire() does not run after cancel () returns, // but dont require that lock is applied while calling expire() { - epicsAutoMutexRelease autoRelease ( this->queue.mutex ); + epicsAutoMutexRelease autoRelease ( locker ); while ( this->queue.cancelPending ) { this->queue.cancelBlockingEvent.wait (); } diff --git a/src/libCom/timer/timerPrivate.h b/src/libCom/timer/timerPrivate.h index d49976051..5b669cc85 100644 --- a/src/libCom/timer/timerPrivate.h +++ b/src/libCom/timer/timerPrivate.h @@ -60,7 +60,7 @@ private: epicsTimerNotify *pNotify; // callback timerQueue &queue; void privateStart ( epicsTimerNotify & notify, const epicsTime & ); - void privateCancel (); + void privateCancel ( epicsAutoMutex & ); timer & operator = ( const timer & ); friend class timerQueue; }; diff --git a/src/libCom/timer/timerQueueActive.cpp b/src/libCom/timer/timerQueueActive.cpp index fc3ef878f..beab3e7f4 100644 --- a/src/libCom/timer/timerQueueActive.cpp +++ b/src/libCom/timer/timerQueueActive.cpp @@ -41,7 +41,7 @@ epicsTimerQueueActive &epicsTimerQueueActive::allocate ( bool okToShare, unsigne } timerQueueActive::timerQueueActive ( bool okToShareIn, unsigned priority ) : - queue ( *this ), thread ( *this, "epicsTimerQueueActive", + queue ( *this ), thread ( *this, "timerQueue", epicsThreadGetStackSize ( epicsThreadStackMedium ), priority ), okToShare ( okToShareIn ), exitFlag ( false ), terminateFlag ( false ) {