From bddf3b244979886f615909fde9cb1114e7152d0f Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Wed, 7 Mar 2001 16:40:07 +0000 Subject: [PATCH] upgraded locking --- src/cas/generic/caServerI.cc | 68 +++++++++++++++++------------------ src/cas/generic/caServerIIL.h | 21 +++++++---- src/cas/generic/outBufIL.h | 6 ++-- src/cas/generic/server.h | 15 ++++---- 4 files changed, 59 insertions(+), 51 deletions(-) diff --git a/src/cas/generic/caServerI.cc b/src/cas/generic/caServerI.cc index 18e340036..7f57540e2 100644 --- a/src/cas/generic/caServerI.cc +++ b/src/cas/generic/caServerI.cc @@ -103,8 +103,7 @@ caServerI::caServerI (caServer &tool, unsigned nPV) : */ caServerI::~caServerI() { - - this->lock(); + epicsAutoMutex locker ( this->mutex ); // // delete all clients @@ -124,8 +123,6 @@ caServerI::~caServerI() while ( (pIF = this->intfList.get()) ) { delete pIF; } - - this->unlock(); } // @@ -133,9 +130,8 @@ caServerI::~caServerI() // void caServerI::installClient(casStrmClient *pClient) { - this->lock(); + epicsAutoMutex locker ( this->mutex ); this->clientList.add(*pClient); - this->unlock(); } // @@ -143,9 +139,8 @@ void caServerI::installClient(casStrmClient *pClient) // void caServerI::removeClient (casStrmClient *pClient) { - this->lock(); + epicsAutoMutex locker ( this->mutex ); this->clientList.remove (*pClient); - this->unlock(); } // @@ -224,9 +219,10 @@ caStatus caServerI::attachInterface (const caNetAddr &addr, bool autoBeaconAddr, return S_cas_noMemory; } - this->lock (); - this->intfList.add (*pIntf); - this->unlock (); + { + epicsAutoMutex locker ( this->mutex ); + this->intfList.add (*pIntf); + } return S_cas_success; } @@ -244,13 +240,14 @@ void caServerI::sendBeacon() // otherwise. Also send a beacon to all configured // addresses. // - this->lock(); - tsDLIterBD iter = this->intfList.firstIter (); - while ( iter.valid () ) { - iter->sendBeacon (); - iter++; - } - this->unlock(); + { + epicsAutoMutex locker ( this->mutex ); + tsDLIterBD iter = this->intfList.firstIter (); + while ( iter.valid () ) { + iter->sendBeacon (); + iter++; + } + } // // double the period between beacons (but dont exceed max) @@ -276,23 +273,23 @@ void caServerI::show (unsigned level) const printf( "Channel Access Server Status V%d.%d\n", CA_PROTOCOL_VERSION, CA_MINOR_VERSION); - this->epicsMutex::show(level); + this->mutex.show(level); - this->lock(); - tsDLIterConstBD iterCl = this->clientList.firstIter (); - while ( iterCl.valid () ) { - iterCl->show (level); - ++iterCl; + { + epicsAutoMutex locker ( this->mutex ); + tsDLIterConstBD iterCl = this->clientList.firstIter (); + while ( iterCl.valid () ) { + iterCl->show (level); + ++iterCl; + } + + tsDLIterConstBD iterIF = this->intfList.firstIter (); + while ( iterIF.valid () ) { + iterIF->casIntfOS::show ( level ); + ++iterIF; + } } - tsDLIterConstBD iterIF = this->intfList.firstIter (); - while ( iterIF.valid () ) { - iterIF->casIntfOS::show ( level ); - ++iterIF; - } - - this->unlock(); - bytes_reserved = 0u; #if 0 bytes_reserved += sizeof(casClient) * @@ -318,9 +315,10 @@ void caServerI::show (unsigned level) const #endif printf( "The server's integer resource id conversion table:\n"); - this->lock(); - this->chronIntIdResTable::show(level); - this->unlock(); + { + epicsAutoMutex locker ( this->mutex ); + this->chronIntIdResTable::show(level); + } } return; diff --git a/src/cas/generic/caServerIIL.h b/src/cas/generic/caServerIIL.h index ec7382073..9e243a83b 100644 --- a/src/cas/generic/caServerIIL.h +++ b/src/cas/generic/caServerIIL.h @@ -54,16 +54,14 @@ inline caServer * caServerI::operator -> () inline casRes *caServerI::lookupRes(const caResId &idIn, casResType type) { chronIntId tmpId (idIn); - casRes *pRes; - this->lock(); - pRes = this->chronIntIdResTable::lookup (tmpId); - if (pRes) { - if (pRes->resourceType()!=type) { + epicsAutoMutex locker ( this->mutex ); + casRes *pRes = this->chronIntIdResTable::lookup ( tmpId ); + if ( pRes ) { + if ( pRes->resourceType() != type ) { pRes = NULL; } } - this->unlock(); return pRes; } @@ -179,5 +177,16 @@ inline void caServerI::clearEventsPostedCounter (void) this->nEventsPosted = 0u; } +inline void caServerI::lock () const +{ + this->mutex.lock (); +} + +inline void caServerI::unlock () const +{ + this->mutex.unlock (); +} + + #endif // caServerIIL_h diff --git a/src/cas/generic/outBufIL.h b/src/cas/generic/outBufIL.h index cafd4f959..cd765c270 100644 --- a/src/cas/generic/outBufIL.h +++ b/src/cas/generic/outBufIL.h @@ -13,9 +13,8 @@ inline bufSizeT outBuf::bytesPresent () const // This guarantees that any pushCtx() operation // in progress completes before another thread checks. // - this->mutex.lock (); + epicsAutoMutex locker ( this->mutex ); bufSizeT result = this->stack; - this->mutex.unlock (); return result; } @@ -30,9 +29,8 @@ inline void outBuf::clear () // in progress completes before another thread // clears. // - this->mutex.lock (); + epicsAutoMutex locker ( this->mutex ); this->stack = 0u; - this->mutex.unlock (); } // diff --git a/src/cas/generic/server.h b/src/cas/generic/server.h index 9d0f78405..1c5958027 100644 --- a/src/cas/generic/server.h +++ b/src/cas/generic/server.h @@ -389,11 +389,11 @@ protected: void clear (); private: - epicsMutex mutex; - char *pBuf; - bufSizeT bufSize; - bufSizeT stack; - unsigned ctxRecursCount; + mutable epicsMutex mutex; + char *pBuf; + bufSizeT bufSize; + bufSizeT stack; + unsigned ctxRecursCount; virtual unsigned getDebugLevel() const = 0; virtual void sendBlockSignal() = 0; @@ -815,7 +815,6 @@ class casClientMon; // caServerI // class caServerI : - public epicsMutex, public caServerOS, public caServerIO, public ioBlockedList, @@ -885,9 +884,13 @@ public: void incrEventsPostedCounter (void); void clearEventsPostedCounter (void); + void lock () const; + void unlock () const; + private: void advanceBeaconPeriod(); + mutable epicsMutex mutex; tsDLList clientList; tsDLList intfList; double maxBeaconInterval;