From 6c4c0636921de8e30f657ce19d03462e7458ce83 Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Thu, 21 Aug 2003 00:18:31 +0000 Subject: [PATCH] workaround for bug in RH 7.3 Linux --- src/libCom/osi/epicsMutex.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/libCom/osi/epicsMutex.cpp b/src/libCom/osi/epicsMutex.cpp index 94c7cfb62..e7d263bf7 100644 --- a/src/libCom/osi/epicsMutex.cpp +++ b/src/libCom/osi/epicsMutex.cpp @@ -236,12 +236,21 @@ void epicsMutex :: show ( unsigned level ) const } static epicsThreadPrivate < epicsDeadlockDetectMutex > - currentMutexLevel; + * pCurrentMutexLevel = 0; + +static epicsThreadOnceId epicsDeadlockDetectMutexInit = EPICS_THREAD_ONCE_INIT; + +static void epicsDeadlockDetectMutexInitFunc ( void * ) +{ + pCurrentMutexLevel = new epicsThreadPrivate < epicsDeadlockDetectMutex > (); +} epicsDeadlockDetectMutex:: epicsDeadlockDetectMutex ( hierarchyLevel_t level ) : hierarchyLevel ( level ), pPreviousLevel ( 0 ) { + epicsThreadOnce ( & epicsDeadlockDetectMutexInit, + epicsDeadlockDetectMutexInitFunc, 0 ); } epicsDeadlockDetectMutex::~epicsDeadlockDetectMutex () @@ -255,7 +264,7 @@ void epicsDeadlockDetectMutex::show ( unsigned level ) const void epicsDeadlockDetectMutex::lock () { - epicsDeadlockDetectMutex * pPrev = currentMutexLevel.get(); + epicsDeadlockDetectMutex * pPrev = pCurrentMutexLevel->get(); if ( pPrev && pPrev != this ) { if ( pPrev->hierarchyLevel >= this->hierarchyLevel ) { errlogPrintf ( "!!!! Deadlock Vulnerability Detected !!!! " @@ -266,14 +275,14 @@ void epicsDeadlockDetectMutex::lock () } this->mutex.lock (); if ( pPrev && pPrev != this ) { - currentMutexLevel.set ( this ); + pCurrentMutexLevel->set ( this ); this->pPreviousLevel = pPrev; } } void epicsDeadlockDetectMutex::unlock () { - currentMutexLevel.set ( this->pPreviousLevel ); + pCurrentMutexLevel->set ( this->pPreviousLevel ); this->mutex.unlock (); } @@ -281,8 +290,8 @@ bool epicsDeadlockDetectMutex::tryLock () { bool success = this->mutex.tryLock (); if ( success ) { - this->pPreviousLevel = currentMutexLevel.get(); - currentMutexLevel.set ( this ); + this->pPreviousLevel = pCurrentMutexLevel->get(); + pCurrentMutexLevel->set ( this ); } return success; }