diff --git a/src/ca/cac.cpp b/src/ca/cac.cpp index 108608e63..18b537897 100644 --- a/src/ca/cac.cpp +++ b/src/ca/cac.cpp @@ -299,27 +299,15 @@ void cac::processRecvBacklog () while ( piiu.valid () ) { tsDLIterBD < tcpiiu > pNext = piiu; pNext++; - if ( ! piiu->alive () ) { - assert ( this->pudpiiu && this->pSearchTmr ); - - piiu->getBHE().unbindFromIIU (); - if ( piiu->channelCount () ) { char hostNameTmp[64]; piiu->hostName ( hostNameTmp, sizeof ( hostNameTmp ) ); genLocalExcep ( *this, ECA_DISCONN, hostNameTmp ); } - + piiu->getBHE().unbindFromIIU (); + assert ( this->pudpiiu ); piiu->disconnectAllChan ( *this->pudpiiu ); - - // make certain that: - // 1) this is called from the appropriate thread - // 2) lock is not held while in call back - if ( ! this->enablePreemptiveCallback ) { - epicsAutoMutexRelease autoRelease ( this->mutex ); - this->notify.fdWasDestroyed ( piiu->getSock() ); - } this->iiuList.remove ( *piiu ); deadIIU.add ( *piiu ); // postpone destroy and avoid deadlock } @@ -333,7 +321,6 @@ void cac::processRecvBacklog () } piiu->processIncoming (); } - piiu = pNext; } } @@ -341,9 +328,16 @@ void cac::processRecvBacklog () { epicsAutoMutex autoRelease ( this->mutex ); while ( tcpiiu *piiu = deadIIU.get() ) { + // make certain that: + // 1) this is called from the appropriate thread + // 2) lock is not held while in call back + if ( ! this->enablePreemptiveCallback ) { + this->notify.fdWasDestroyed ( piiu->getSock() ); + } piiu->destroy (); } } + assert ( this->pSearchTmr ); this->pSearchTmr->resetPeriod ( 0.0 ); } } @@ -687,27 +681,14 @@ void cac::startRecvProcessThread () void cac::run () { epicsAutoMutex autoMutex ( this->mutex ); - this->attachToClientCtx (); - while ( ! this->recvProcessThreadExitRequest ) { - - { - if ( this->recvProcessEnableRefCount ) { - this->recvProcessInProgress = true; - } - } - - if ( this->recvProcessInProgress ) { + if ( this->recvProcessEnableRefCount ) { + this->recvProcessInProgress = true; this->processRecvBacklog (); - } - - bool signalNeeded; - { this->recvProcessInProgress = false; - signalNeeded = this->recvProcessCompletionNBlockers > 0u; } - + bool signalNeeded = this->recvProcessCompletionNBlockers > 0u; { epicsAutoMutexRelease autoRelease ( this->mutex ); if ( signalNeeded ) { diff --git a/src/ca/cac.h b/src/ca/cac.h index 9b593ea8e..306aed46b 100644 --- a/src/ca/cac.h +++ b/src/ca/cac.h @@ -295,11 +295,13 @@ inline void cac::attachToClientCtx () inline char * cac::allocateSmallBufferTCP () { + // this locks internally return ( char * ) freeListMalloc ( this->tcpSmallRecvBufFreeList ); } inline void cac::releaseSmallBufferTCP ( char *pBuf ) { + // this locks internally freeListFree ( this->tcpSmallRecvBufFreeList, pBuf ); } @@ -310,11 +312,13 @@ inline unsigned cac::largeBufferSizeTCP () const inline char * cac::allocateLargeBufferTCP () { + // this locks internally return ( char * ) freeListMalloc ( this->tcpLargeRecvBufFreeList ); } inline void cac::releaseLargeBufferTCP ( char *pBuf ) { + // this locks internally freeListFree ( this->tcpLargeRecvBufFreeList, pBuf ); } diff --git a/src/ca/tcpiiu.cpp b/src/ca/tcpiiu.cpp index 475c97e4d..7c5be2f0c 100644 --- a/src/ca/tcpiiu.cpp +++ b/src/ca/tcpiiu.cpp @@ -637,23 +637,14 @@ tcpiiu::~tcpiiu () } } - /* - * free message body cache - */ - { - epicsAutoMutex autoMutex ( this->pCAC()->mutexRef() ); - - if ( this->pCurData ) { - if ( this->curDataMax == MAX_TCP ) { - this->pCAC()->releaseSmallBufferTCP ( this->pCurData ); - } - else { - this->pCAC()->releaseLargeBufferTCP ( this->pCurData ); - } + // free message body cache + if ( this->pCurData ) { + if ( this->curDataMax == MAX_TCP ) { + this->pCAC()->releaseSmallBufferTCP ( this->pCurData ); + } + else { + this->pCAC()->releaseLargeBufferTCP ( this->pCurData ); } - - this->sendQue.clear (); - this->recvQue.clear (); } // wakeup user threads blocking for send backlog to be reduced