added throw specifications

This commit is contained in:
Jeff Hill
2002-10-23 22:20:49 +00:00
parent f2ccfaf1de
commit e1e2df53ad
2 changed files with 37 additions and 21 deletions

View File

@@ -37,7 +37,7 @@ typedef struct mutexNode {
int lineno;
}mutexNode;
STATIC epicsMutexId lock;
STATIC epicsMutexId epicsMutexGlobalLock;
epicsMutexId epicsShareAPI epicsMutexOsiCreate(
const char *pFileName,int lineno)
@@ -49,9 +49,9 @@ epicsMutexId epicsShareAPI epicsMutexOsiCreate(
firstTime=0;
ellInit(&mutexList);
ellInit(&freeList);
lock = epicsMutexOsdCreate();
epicsMutexGlobalLock = epicsMutexOsdCreate();
}
epicsMutexMustLock(lock);
epicsMutexMustLock(epicsMutexGlobalLock);
id = epicsMutexOsdCreate();
if(id) {
pmutexNode = (mutexNode *)ellFirst(&freeList);
@@ -65,7 +65,7 @@ epicsMutexId epicsShareAPI epicsMutexOsiCreate(
pmutexNode->lineno = lineno;
ellAdd(&mutexList,&pmutexNode->node);
}
epicsMutexUnlock(lock);
epicsMutexUnlock(epicsMutexGlobalLock);
return(id);
}
@@ -81,19 +81,19 @@ void epicsShareAPI epicsMutexDestroy(epicsMutexId id)
{
mutexNode *pmutexNode;
epicsMutexMustLock(lock);
epicsMutexMustLock(epicsMutexGlobalLock);
pmutexNode = (mutexNode *)ellLast(&mutexList);
while(pmutexNode) {
if(id==pmutexNode->id) {
ellDelete(&mutexList,&pmutexNode->node);
ellAdd(&freeList,&pmutexNode->node);
epicsMutexOsdDestroy(pmutexNode->id);
epicsMutexUnlock(lock);
epicsMutexUnlock(epicsMutexGlobalLock);
return;
}
pmutexNode = (mutexNode *)ellPrevious(&pmutexNode->node);
}
epicsMutexUnlock(lock);
epicsMutexUnlock(epicsMutexGlobalLock);
errlogPrintf("epicsMutexDestroy Did not find epicsMutexId\n");
}
@@ -104,7 +104,7 @@ void epicsShareAPI epicsMutexShowAll(int onlyLocked,unsigned int level)
if(firstTime) return;
printf("ellCount(&mutexList) %d ellCount(&freeList) %d\n",
ellCount(&mutexList),ellCount(&freeList));
epicsMutexMustLock(lock);
epicsMutexMustLock(epicsMutexGlobalLock);
pmutexNode = (mutexNode *)ellFirst(&mutexList);
while(pmutexNode) {
if(onlyLocked) {
@@ -121,11 +121,11 @@ void epicsShareAPI epicsMutexShowAll(int onlyLocked,unsigned int level)
epicsMutexShow(pmutexNode->id,level);
pmutexNode = (mutexNode *)ellNext(&pmutexNode->node);
}
epicsMutexUnlock(lock);
epicsMutexUnlock(epicsMutexGlobalLock);
}
epicsMutex :: epicsMutex () :
epicsMutex :: epicsMutex () throw ( std::bad_alloc ) :
id ( epicsMutexCreate () )
{
if ( this->id == 0 ) {
@@ -133,17 +133,20 @@ epicsMutex :: epicsMutex () :
}
}
epicsMutex ::~epicsMutex ()
epicsMutex ::~epicsMutex ()
throw ()
{
epicsMutexDestroy ( this->id );
}
void epicsMutex :: show ( unsigned level ) const
void epicsMutex :: show ( unsigned level ) const
throw ()
{
epicsMutexShow ( this->id, level );
}
void epicsMutex :: throwInvalidSemaphore ()
throw ( epicsMutex::invalidSemaphore )
{
throw invalidSemaphore ();
}

View File

@@ -21,20 +21,29 @@ typedef enum {
#ifdef __cplusplus
#include <stdexcept>
class epicsMutex {
public:
epicsShareFunc epicsMutex ();
epicsShareFunc ~epicsMutex ();
epicsShareFunc void show ( unsigned level ) const;
void lock (); /* blocks until success */
void unlock ();
bool lock ( double timeOut ); /* true if successful */
bool tryLock (); /* true if successful */
class invalidSemaphore {}; // exception
epicsShareFunc epicsMutex ()
throw ( std::bad_alloc );
epicsShareFunc ~epicsMutex ()
throw ();
epicsShareFunc void show ( unsigned level ) const
throw ();
void lock () /* blocks until success */
throw ( invalidSemaphore );
void unlock ()
throw ();
bool lock ( double timeOut ) /* true if successful */
throw ( invalidSemaphore );
bool tryLock () /* true if successful */
throw ( invalidSemaphore );
private:
epicsMutexId id;
epicsShareFunc static void throwInvalidSemaphore ();
epicsShareFunc static void throwInvalidSemaphore ()
throw ( invalidSemaphore );
epicsMutex ( const epicsMutex & );
epicsMutex & operator = ( const epicsMutex & );
};
@@ -82,6 +91,7 @@ epicsShareFunc void epicsShareAPI epicsMutexShowAll(
#ifdef __cplusplus
inline void epicsMutex::lock ()
throw ( epicsMutex::invalidSemaphore )
{
epicsMutexLockStatus status = epicsMutexLock ( this->id );
if ( status != epicsMutexLockOK ) {
@@ -90,6 +100,7 @@ inline void epicsMutex::lock ()
}
inline bool epicsMutex::lock ( double timeOut ) // X aCC 361
throw ( epicsMutex::invalidSemaphore )
{
epicsMutexLockStatus status = epicsMutexLockWithTimeout ( this->id, timeOut );
if ( status == epicsMutexLockOK ) {
@@ -105,6 +116,7 @@ inline bool epicsMutex::lock ( double timeOut ) // X aCC 361
}
inline bool epicsMutex::tryLock () // X aCC 361
throw ( epicsMutex::invalidSemaphore )
{
epicsMutexLockStatus status = epicsMutexTryLock ( this->id );
if ( status == epicsMutexLockOK ) {
@@ -120,6 +132,7 @@ inline bool epicsMutex::tryLock () // X aCC 361
}
inline void epicsMutex::unlock ()
throw ()
{
epicsMutexUnlock ( this->id );
}