upgraded locking

This commit is contained in:
Jeff Hill
2001-03-07 16:40:07 +00:00
parent b5f8bf2381
commit bddf3b2449
4 changed files with 59 additions and 51 deletions
+33 -35
View File
@@ -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 <casIntfOS> iter = this->intfList.firstIter ();
while ( iter.valid () ) {
iter->sendBeacon ();
iter++;
}
this->unlock();
{
epicsAutoMutex locker ( this->mutex );
tsDLIterBD <casIntfOS> 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<casStrmClient> iterCl = this->clientList.firstIter ();
while ( iterCl.valid () ) {
iterCl->show (level);
++iterCl;
{
epicsAutoMutex locker ( this->mutex );
tsDLIterConstBD<casStrmClient> iterCl = this->clientList.firstIter ();
while ( iterCl.valid () ) {
iterCl->show (level);
++iterCl;
}
tsDLIterConstBD<casIntfOS> iterIF = this->intfList.firstIter ();
while ( iterIF.valid () ) {
iterIF->casIntfOS::show ( level );
++iterIF;
}
}
tsDLIterConstBD<casIntfOS> 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<casRes>::show(level);
this->unlock();
{
epicsAutoMutex locker ( this->mutex );
this->chronIntIdResTable<casRes>::show(level);
}
}
return;
+15 -6
View File
@@ -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<casRes>::lookup (tmpId);
if (pRes) {
if (pRes->resourceType()!=type) {
epicsAutoMutex locker ( this->mutex );
casRes *pRes = this->chronIntIdResTable<casRes>::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
+2 -4
View File
@@ -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 ();
}
//
+9 -6
View File
@@ -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<casStrmClient> clientList;
tsDLList<casIntfOS> intfList;
double maxBeaconInterval;