From 47dc34084aac9e4e5381e53a5e03f417028cef0c Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Thu, 21 Mar 2002 22:21:34 +0000 Subject: [PATCH] moved epicsMutex.c to epicsMutex.cpp --- .../osi/{epicsMutex.c => epicsMutex.cpp} | 64 ++++++++++++++++++- 1 file changed, 62 insertions(+), 2 deletions(-) rename src/libCom/osi/{epicsMutex.c => epicsMutex.cpp} (70%) diff --git a/src/libCom/osi/epicsMutex.c b/src/libCom/osi/epicsMutex.cpp similarity index 70% rename from src/libCom/osi/epicsMutex.c rename to src/libCom/osi/epicsMutex.cpp index 2fbd3fc9a..c708e2fa7 100644 --- a/src/libCom/osi/epicsMutex.c +++ b/src/libCom/osi/epicsMutex.cpp @@ -1,5 +1,5 @@ /* epicsMutex.c */ -/* Author: Marty Kraimer Date: 03APR01 */ +/* Author: Marty Kraimer and Jeff Hill Date: 03APR01 */ /***************************************************************** COPYRIGHT NOTIFICATION ***************************************************************** @@ -12,6 +12,8 @@ described on the COPYRIGHT_Combined file included as part of this distribution. **********************************************************************/ +#include + #include #include #include @@ -58,7 +60,7 @@ epicsMutexId epicsShareAPI epicsMutexOsiCreate( if(pmutexNode) { ellDelete(&freeList,&pmutexNode->node); } else { - pmutexNode = calloc(1,sizeof(mutexNode)); + pmutexNode = static_cast ( calloc(1,sizeof(mutexNode)) ); } pmutexNode->id = id; pmutexNode->pFileName = pFileName; @@ -123,3 +125,61 @@ void epicsShareAPI epicsMutexShowAll(int onlyLocked,unsigned int level) } epicsMutexUnlock(lock); } + + +epicsMutex :: epicsMutex () : + id ( epicsMutexCreate () ) +{ + if ( this->id == 0 ) { + throw std::bad_alloc (); + } +} + +epicsMutex ::~epicsMutex () +{ + epicsMutexDestroy ( this->id ); +} + +void epicsMutex :: lock () +{ + epicsMutexLockStatus status = epicsMutexLock ( this->id ); + if ( status != epicsMutexLockOK ) { + throwWithLocation ( invalidSemaphore () ); + } +} + +bool epicsMutex :: lock ( double timeOut ) +{ + epicsMutexLockStatus status = epicsMutexLockWithTimeout ( this->id, timeOut ); + if (status==epicsMutexLockOK) { + return true; + } else if (status==epicsMutexLockTimeout) { + return false; + } else { + throwWithLocation ( invalidSemaphore () ); + } + return false; // never here, compiler is happy +} + +bool epicsMutex :: tryLock () +{ + epicsMutexLockStatus status = epicsMutexTryLock ( this->id ); + if ( status == epicsMutexLockOK ) { + return true; + } else if ( status == epicsMutexLockTimeout ) { + return false; + } else { + throwWithLocation ( invalidSemaphore () ); + } + return false; // never here, but compiler is happy +} + +void epicsMutex :: unlock () +{ + epicsMutexUnlock ( this->id ); +} + +void epicsMutex :: show ( unsigned level ) const +{ + epicsMutexShow ( this->id, level ); +} \ No newline at end of file