From db52f124b9e8dfc10dd4e5ea992567a8d041ef1d Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Fri, 15 Sep 2000 17:32:24 +0000 Subject: [PATCH] improved management of per channel IO list --- src/ca/baseNMIU.cpp | 24 ++++++++++++++++++++---- src/ca/cac.cpp | 20 +++++++++++++------- src/ca/cacPrivateListOfIO.cpp | 14 ++++++++++++++ src/ca/iocinf.h | 15 ++++++++++----- src/ca/nciu_IL.h | 8 +++++--- src/ca/netReadCopyIO.cpp | 2 +- src/ca/netSubscription.cpp | 2 +- 7 files changed, 64 insertions(+), 21 deletions(-) diff --git a/src/ca/baseNMIU.cpp b/src/ca/baseNMIU.cpp index 8b81cfd71..3072f9840 100644 --- a/src/ca/baseNMIU.cpp +++ b/src/ca/baseNMIU.cpp @@ -13,19 +13,34 @@ #include "iocinf.h" #include "nciu_IL.h" -baseNMIU::baseNMIU ( nciu &chanIn ) : chan ( chanIn ) +osiMutex baseNMIU::mutex; + +baseNMIU::baseNMIU ( nciu &chanIn ) : + chan ( chanIn ), attachedToChannel ( true ) { chanIn.ioInstall ( *this ); } baseNMIU::~baseNMIU () { - // private NOOP forces pool allocation + this->uninstallFromChannel (); +} + +void baseNMIU::uninstallFromChannel () +{ + this->mutex.lock (); + bool attached = this->attachedToChannel; + this->attachedToChannel = false; + this->mutex.unlock (); + + if ( attached ) { + this->chan.ioUninstall ( *this ); + } } void baseNMIU::destroy () { - this->chan.ioDestroy ( this->getId () ); + delete this; } int baseNMIU::subscriptionMsg () @@ -35,5 +50,6 @@ int baseNMIU::subscriptionMsg () void baseNMIU::show ( unsigned /* level */ ) const { - printf ( "CA IO primitive at %p for channel %s\n", this, chan.pName () ); + printf ( "CA IO primitive at %p for channel %s\n", + this, this->chan.pName () ); } diff --git a/src/ca/cac.cpp b/src/ca/cac.cpp index 76b9ddc8b..80a6c7bf8 100644 --- a/src/ca/cac.cpp +++ b/src/ca/cac.cpp @@ -630,11 +630,17 @@ bool cac::ioComplete () const } } -void cac::ioInstall ( nciu &chan, baseNMIU &io ) +void cac::ioInstall ( baseNMIU &io ) { this->defaultMutex.lock (); this->ioTable.add ( io ); - chan.cacPrivateListOfIO::eventq.add ( io ); + this->defaultMutex.unlock (); +} + +void cac::ioUninstall ( unsigned id ) +{ + this->defaultMutex.lock (); + this->ioTable.remove ( id ); this->defaultMutex.unlock (); } @@ -643,7 +649,7 @@ void cac::ioDestroy ( unsigned id ) this->defaultMutex.lock (); baseNMIU * pmiu = this->ioTable.remove ( id ); if ( pmiu ) { - pmiu->chan.cacPrivateListOfIO::eventq.remove ( *pmiu ); + pmiu->uninstallFromChannel (); } this->defaultMutex.unlock (); // care is taken to not destroy with the cac lock @@ -703,7 +709,7 @@ void cac::ioCompletionNotifyAndDestroy ( unsigned id ) this->defaultMutex.lock (); baseNMIU * pmiu = this->ioTable.remove ( id ); if ( pmiu ) { - pmiu->chan.cacPrivateListOfIO::eventq.remove ( *pmiu ); + pmiu->uninstallFromChannel (); } this->defaultMutex.unlock (); // care is taken to not destroy with the cac lock @@ -723,7 +729,7 @@ void cac::ioCompletionNotifyAndDestroy ( unsigned id, this->defaultMutex.lock (); baseNMIU * pmiu = this->ioTable.remove ( id ); if ( pmiu ) { - pmiu->chan.cacPrivateListOfIO::eventq.remove ( *pmiu ); + pmiu->uninstallFromChannel (); } this->defaultMutex.unlock (); // care is taken to not destroy with the cac lock @@ -742,7 +748,7 @@ void cac::ioExceptionNotifyAndDestroy ( unsigned id, int status, const char *pCo this->defaultMutex.lock (); baseNMIU * pmiu = this->ioTable.remove ( id ); if ( pmiu ) { - pmiu->chan.cacPrivateListOfIO::eventq.remove ( *pmiu ); + pmiu->uninstallFromChannel (); } this->defaultMutex.unlock (); // care is taken to not destroy with the cac lock @@ -762,7 +768,7 @@ void cac::ioExceptionNotifyAndDestroy ( unsigned id, int status, this->defaultMutex.lock (); baseNMIU * pmiu = this->ioTable.remove ( id ); if ( pmiu ) { - pmiu->chan.cacPrivateListOfIO::eventq.remove ( *pmiu ); + pmiu->uninstallFromChannel (); } this->defaultMutex.unlock (); // care is taken to not destroy with the cac lock diff --git a/src/ca/cacPrivateListOfIO.cpp b/src/ca/cacPrivateListOfIO.cpp index 614a23f7f..93f71631f 100644 --- a/src/ca/cacPrivateListOfIO.cpp +++ b/src/ca/cacPrivateListOfIO.cpp @@ -22,6 +22,20 @@ cacPrivateListOfIO::cacPrivateListOfIO ( cac &cacIn ) : { } +void cacPrivateListOfIO::addIO ( baseNMIU &io ) +{ + this->cacCtx.cacPrivateListOfIOPrivate::mutex.lock (); + this->eventq.add ( io ); + this->cacCtx.cacPrivateListOfIOPrivate::mutex.unlock (); +} + +void cacPrivateListOfIO::removeIO ( baseNMIU &io ) +{ + this->cacCtx.cacPrivateListOfIOPrivate::mutex.lock (); + this->eventq.remove ( io ); + this->cacCtx.cacPrivateListOfIOPrivate::mutex.unlock (); +} + // Destroy all IO blocks attached. // Care is taken here not to hold the lock while // sending a subscription delete message (which diff --git a/src/ca/iocinf.h b/src/ca/iocinf.h index 2096dda52..444cd9ccd 100644 --- a/src/ca/iocinf.h +++ b/src/ca/iocinf.h @@ -241,6 +241,7 @@ private: }; class cac; +class baseNMIU; class cacPrivateListOfIO { public: @@ -248,15 +249,16 @@ public: void destroyAllIO (); void subscribeAllIO (); void disconnectAllIO ( const char *pHostName ); + void addIO ( baseNMIU &io ); + void removeIO ( baseNMIU &io ); protected: cac &cacCtx; private: tsDLList < class baseNMIU > eventq; - friend class cac; }; class nciu : public cacChannelIO, public tsDLNode < nciu >, - public chronIntIdRes < nciu >, public cacPrivateListOfIO { + public chronIntIdRes < nciu >, private cacPrivateListOfIO { public: nciu ( class cac &cac, cacChannel &chan, const char *pNameIn ); void destroy (); @@ -301,7 +303,7 @@ public: void attachChanToIIU ( netiiu &iiu ); void detachChanFromIIU (); void ioInstall ( class baseNMIU & ); - void ioDestroy ( unsigned id ); + void ioUninstall ( class baseNMIU & ); bool setClaimMsgCache ( class claimMsgCache & ); void show ( unsigned level ) const; @@ -346,10 +348,12 @@ public: virtual void show ( unsigned level ) const; virtual int subscriptionMsg (); void destroy (); + void uninstallFromChannel (); protected: virtual ~baseNMIU (); // must be allocated from pool nciu &chan; - friend class cac; + bool attachedToChannel; + static osiMutex mutex; }; class netSubscription : private cacNotifyIO, private baseNMIU { @@ -1009,8 +1013,9 @@ public: // IO management routines bool ioComplete () const; + void ioInstall ( baseNMIU &io ); + void ioUninstall ( unsigned id ); void ioDestroy ( unsigned id ); - void ioInstall ( nciu &chan, baseNMIU &io ); void ioCompletionNotify ( unsigned id ); void ioCompletionNotify ( unsigned id, unsigned type, unsigned long count, const void *pData ); diff --git a/src/ca/nciu_IL.h b/src/ca/nciu_IL.h index 87a047ace..a92e85933 100644 --- a/src/ca/nciu_IL.h +++ b/src/ca/nciu_IL.h @@ -161,11 +161,13 @@ inline bool nciu::connectionInProgress ( const osiSockAddr &addrIn ) inline void nciu::ioInstall ( class baseNMIU &nmiu ) { - this->cacCtx.ioInstall ( *this, nmiu ); + this->addIO ( nmiu ); + this->cacCtx.ioInstall ( nmiu ); } -inline void nciu::ioDestroy ( unsigned idIn ) +inline void nciu::ioUninstall ( class baseNMIU &nmiu ) { - this->cacCtx.ioDestroy ( idIn ); + this->cacCtx.ioUninstall ( nmiu.getId () ); + this->removeIO ( nmiu ); } diff --git a/src/ca/netReadCopyIO.cpp b/src/ca/netReadCopyIO.cpp index 66018df06..67e9c6c3b 100644 --- a/src/ca/netReadCopyIO.cpp +++ b/src/ca/netReadCopyIO.cpp @@ -51,7 +51,7 @@ void netReadCopyIO::completionNotify ( unsigned typeIn, memcpy ( this->pValue, pDataIn, dbr_size_n ( typeIn, countIn ) ); # endif - this->chan.decrementOutstandingIO (this->seqNumber); + this->chan.decrementOutstandingIO ( this->seqNumber ); } else { this->exceptionNotify ( ECA_INTERNAL, "bad data type in message" ); diff --git a/src/ca/netSubscription.cpp b/src/ca/netSubscription.cpp index a8716adaf..975bc4ad1 100644 --- a/src/ca/netSubscription.cpp +++ b/src/ca/netSubscription.cpp @@ -31,7 +31,7 @@ netSubscription::~netSubscription () void netSubscription::destroy() { - this->baseNMIU::destroy (); + delete this; } int netSubscription::subscriptionMsg ()