diff --git a/src/ca/CASG.cpp b/src/ca/CASG.cpp index a2fd6dce5..003102a3a 100644 --- a/src/ca/CASG.cpp +++ b/src/ca/CASG.cpp @@ -31,6 +31,7 @@ #include "oldAccess.h" tsFreeList < struct CASG, 128 > CASG::freeList; +epicsMutex CASG::freeListMutex; CASG::CASG (cac &cacIn) : client (cacIn), magic (CASG_MAGIC), opPendCount (0u), seqNo (0u) @@ -46,13 +47,14 @@ void CASG::destroy () CASG::~CASG () { if ( this->verify () ) { - this->mutex.lock (); - tsDLIterBD notify = this->ioList.firstIter (); - while ( notify.valid () ) { - notify->release (); - notify = this->ioList.firstIter (); + { + epicsAutoMutex locker ( this->mutex ); + tsDLIterBD notify = this->ioList.firstIter (); + while ( notify.valid () ) { + notify->release (); + notify = this->ioList.firstIter (); + } } - this->mutex.unlock (); this->client.uninstallCASG ( *this ); this->magic = 0; } @@ -82,16 +84,6 @@ int CASG::block ( double timeout ) return ECA_TIMEOUT; } - /* - * dont allow recursion - */ - void *p = epicsThreadPrivateGet ( cacRecursionLock ); - if ( p ) { - return ECA_EVDISALLOW; - } - - epicsThreadPrivateSet ( cacRecursionLock, &cacRecursionLock ); - cur_time = epicsTime::getCurrent (); this->client.flush (); @@ -103,17 +95,16 @@ int CASG::block ( double timeout ) status = ECA_NORMAL; while ( 1 ) { - this->mutex.lock (); - if ( this->seqNo != initialSeqNo ) { - this->mutex.unlock (); - break; + { + epicsAutoMutex locker ( this->mutex ); + if ( this->seqNo != initialSeqNo ) { + break; + } + if ( this->opPendCount == 0u ) { + this->seqNo++; + break; + } } - if ( this->opPendCount == 0u ) { - this->seqNo++; - this->mutex.unlock (); - break; - } - this->mutex.unlock (); remaining = timeout - delay; if ( remaining <= CAC_SIGNIFICANT_SELECT_DELAY ) { @@ -122,9 +113,10 @@ int CASG::block ( double timeout ) * recv backlog at least once */ status = ECA_TIMEOUT; - this->mutex.lock (); - this->seqNo++; - this->mutex.unlock (); + { + epicsAutoMutex locker ( this->mutex ); + this->seqNo++; + } break; } @@ -140,32 +132,28 @@ int CASG::block ( double timeout ) this->client.disableCallbackPreemption (); - epicsThreadPrivateSet (cacRecursionLock, NULL); - return status; } void CASG::reset () { - this->mutex.lock (); + epicsAutoMutex locker ( this->mutex ); this->opPendCount = 0; this->seqNo++; - this->mutex.unlock (); } void CASG::show ( unsigned level) const { - printf ("Sync Group: id=%u, magic=%u, opPend=%lu, seqNo=%lu\n", - this->getId (), this->magic, this->opPendCount, this->seqNo); + printf ( "Sync Group: id=%u, magic=%u, opPend=%lu, seqNo=%lu\n", + this->getId (), this->magic, this->opPendCount, this->seqNo ); if ( level ) { - this->mutex.lock (); - tsDLIterConstBD notify = this->ioList.firstIter (); + epicsAutoMutex locker ( this->mutex ); + tsDLIterConstBD < syncGroupNotify > notify = this->ioList.firstIter (); while ( notify.valid () ) { notify->show (level); notify++; } - this->mutex.unlock (); } } @@ -176,11 +164,13 @@ bool CASG::ioComplete () const void * CASG::operator new (size_t size) { + epicsAutoMutex locker ( CASG::freeListMutex ); return CASG::freeList.allocate ( size ); } void CASG::operator delete (void *pCadaver, size_t size) { + epicsAutoMutex locker ( CASG::freeListMutex ); CASG::freeList.release ( pCadaver, size ); } diff --git a/src/ca/cacServiceList.cpp b/src/ca/cacServiceList.cpp index a5a125777..5ce0c863e 100644 --- a/src/ca/cacServiceList.cpp +++ b/src/ca/cacServiceList.cpp @@ -19,44 +19,37 @@ epicsShareDef cacServiceList cacGlobalServiceList; -cacServiceList::cacServiceList () -{ -} - void cacServiceList::registerService ( cacServiceIO &service ) { - this->lock (); + epicsAutoMutex locker ( this->mutex ); this->services.add ( service ); - this->unlock (); } -cacChannelIO * cacServiceList::createChannelIO ( const char *pName, - cac &cacCtx, cacChannelNotify &chan ) +cacChannelIO * cacServiceList::createChannelIO ( + const char *pName, cacChannelNotify &chan ) { cacChannelIO *pChanIO = 0; - this->lock (); + epicsAutoMutex locker ( this->mutex ); tsDLIterBD < cacServiceIO > iter = this->services.firstIter (); while ( iter.valid () ) { - pChanIO = iter->createChannelIO ( pName, cacCtx, chan ); + pChanIO = iter->createChannelIO ( pName, chan ); if ( pChanIO ) { break; } iter++; } - this->unlock (); return pChanIO; } void cacServiceList::show ( unsigned level ) const { - this->lock (); + epicsAutoMutex locker ( this->mutex ); tsDLIterConstBD < cacServiceIO > iter = this->services.firstIter (); while ( iter.valid () ) { iter->show ( level ); iter++; } - this->unlock (); } diff --git a/src/ca/comBuf_IL.h b/src/ca/comBuf_IL.h index 299bd0934..6096f69bb 100644 --- a/src/ca/comBuf_IL.h +++ b/src/ca/comBuf_IL.h @@ -36,11 +36,13 @@ inline void comBuf::destroy () inline void * comBuf::operator new ( size_t size ) { + epicsAutoMutex locker ( comBuf::freeListMutex ); return comBuf::freeList.allocate ( size ); } inline void comBuf::operator delete ( void *pCadaver, size_t size ) { + epicsAutoMutex locker ( comBuf::freeListMutex ); comBuf::freeList.release ( pCadaver, size ); } @@ -116,7 +118,7 @@ inline unsigned comBuf::removeBytes ( unsigned nBytes ) return nBytes; } -inline unsigned comBuf::maxBytes () +inline unsigned comBuf::capacityBytes () { return comBufSize; } diff --git a/src/ca/getCallback.cpp b/src/ca/getCallback.cpp index ae397b64b..026a38364 100644 --- a/src/ca/getCallback.cpp +++ b/src/ca/getCallback.cpp @@ -19,6 +19,7 @@ #include "oldAccess.h" tsFreeList < class getCallback, 1024 > getCallback::freeList; +epicsMutex getCallback::freeListMutex; getCallback::~getCallback () { diff --git a/src/ca/hostNameCache.cpp b/src/ca/hostNameCache.cpp index 88250563b..05004578e 100644 --- a/src/ca/hostNameCache.cpp +++ b/src/ca/hostNameCache.cpp @@ -17,6 +17,7 @@ #include "iocinf.h" tsFreeList < hostNameCache, 16 > hostNameCache::freeList; +epicsMutex hostNameCache::freeListMutex; hostNameCache::hostNameCache ( const osiSockAddr &addr, ipAddrToAsciiEngine &engine ) : ipAddrToAsciiAsynchronous ( addr ), diff --git a/src/ca/msgForMultiplyDefinedPV_IL.h b/src/ca/msgForMultiplyDefinedPV_IL.h index 52da7a12f..e09d3c6ae 100644 --- a/src/ca/msgForMultiplyDefinedPV_IL.h +++ b/src/ca/msgForMultiplyDefinedPV_IL.h @@ -17,10 +17,12 @@ void * msgForMultiplyDefinedPV::operator new ( size_t size ) { + epicsAutoMutex locker ( msgForMultiplyDefinedPV::freeListMutex ); return msgForMultiplyDefinedPV::freeList.allocate ( size ); } void msgForMultiplyDefinedPV::operator delete ( void *pCadaver, size_t size ) { + epicsAutoMutex locker ( msgForMultiplyDefinedPV::freeListMutex ); msgForMultiplyDefinedPV::freeList.release ( pCadaver, size ); }