From 8fd9d6cb8e331cf1971dbf5dc8cb212885026921 Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Wed, 7 Mar 2001 16:15:53 +0000 Subject: [PATCH] installed --- src/ca/getCopy.cpp | 82 ++++++++++++++++++++++++++ src/ca/ioCounterNet.cpp | 126 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 208 insertions(+) create mode 100644 src/ca/getCopy.cpp create mode 100644 src/ca/ioCounterNet.cpp diff --git a/src/ca/getCopy.cpp b/src/ca/getCopy.cpp new file mode 100644 index 000000000..d5b4c1cd8 --- /dev/null +++ b/src/ca/getCopy.cpp @@ -0,0 +1,82 @@ + +/* + * $Id$ + * + * + * L O S A L A M O S + * Los Alamos National Laboratory + * Los Alamos, New Mexico 87545 + * + * Copyright, 1986, The Regents of the University of California. + * + * + * Author Jeffrey O. Hill + * johill@lanl.gov + * 505 665 1831 + */ + +#include "iocinf.h" +#include "oldAccess.h" +#include "cac_IL.h" + +tsFreeList < class getCopy, 1024 > getCopy::freeList; +epicsMutex getCopy::freeListMutex; + +getCopy::getCopy ( cac &cacCtxIn, chtype typeIn, + unsigned long countIn, void *pValueIn ) : + count ( countIn ), cacCtx ( cacCtxIn ), pValue ( pValueIn ), + readSeq ( cacCtxIn.sequenceNumberOfOutstandingIO () ), type ( typeIn ) +{ + cacCtxIn.incrementOutstandingIO (); +} + +getCopy::~getCopy () +{ +} + +void getCopy::release () +{ + delete this; +} + +void getCopy::completionNotify ( cacChannelIO &io ) +{ + this->cacNotify::completionNotify ( io ); +} + +void getCopy::completionNotify ( cacChannelIO &chan, unsigned typeIn, + unsigned long countIn, const void *pDataIn ) +{ + if ( this->type == typeIn ) { + memcpy ( this->pValue, pDataIn, dbr_size_n ( typeIn, countIn ) ); + this->cacCtx.decrementOutstandingIO ( this->readSeq ); + } + else { + this->exceptionNotify ( chan, ECA_INTERNAL, + "bad data type match in get copy back response" ); + } +} + + +void getCopy::exceptionNotify ( cacChannelIO &chan, + int status, const char *pContext ) +{ + this->cacNotify::exceptionNotify ( chan, status, pContext ); +} + +void getCopy::exceptionNotify ( cacChannelIO &chan, + int status, const char *pContext, unsigned type, unsigned long count ) +{ + this->cacNotify::exceptionNotify ( chan, status, pContext, type, count ); +} + +void getCopy::show ( unsigned level ) const +{ + int tmpType = static_cast ( this->type ); + printf ( "read copy IO at %p, type %s, element count %lu\n", + static_cast ( this ), dbf_type_to_text ( tmpType ), this->count ); + if ( level > 0u ) { + printf ( "\tsequence number %u, user's storage %p\n", + this->readSeq, static_cast ( this->pValue ) ); + } +} diff --git a/src/ca/ioCounterNet.cpp b/src/ca/ioCounterNet.cpp new file mode 100644 index 000000000..9a7f779d8 --- /dev/null +++ b/src/ca/ioCounterNet.cpp @@ -0,0 +1,126 @@ + +/* + * $Id$ + * + * + * L O S A L A M O S + * Los Alamos National Laboratory + * Los Alamos, New Mexico 87545 + * + * Copyright, 1986, The Regents of the University of California. + * + * + * Author Jeffrey O. Hill + * johill@lanl.gov + * 505 665 1831 + */ + +#include "iocinf.h" + +ioCounterNet::ioCounterNet () : pndrecvcnt ( 0u ), readSeq ( 0u ) +{ +} + +void ioCounterNet::increment () +{ + epicsAutoMutex locker ( this->mutex ); + if ( this->pndrecvcnt < UINT_MAX ) { + this->pndrecvcnt++; + } + else { + throwWithLocation ( caErrorCode (ECA_INTERNAL) ); + } +} + +unsigned ioCounterNet::sequenceNumber () const +{ + return this->readSeq; +} + +unsigned ioCounterNet::currentCount () const +{ + return this->pndrecvcnt; +} + +void ioCounterNet::waitForCompletion ( double delaySec ) +{ + this->ioDone.wait ( delaySec ); +} + +void ioCounterNet::cleanUp () +{ + epicsAutoMutex locker ( this->mutex ); + this->readSeq++; + this->pndrecvcnt = 0u; +} + +void ioCounterNet::decrement () +{ + bool signalNeeded; + + { + epicsAutoMutex locker ( this->mutex ); + if ( this->pndrecvcnt > 0u ) { + this->pndrecvcnt--; + if ( this->pndrecvcnt == 0u ) { + signalNeeded = true; + } + else { + signalNeeded = false; + } + } + else { + signalNeeded = true; + } + } + + if ( signalNeeded ) { + this->ioDone.signal (); + } +} + +void ioCounterNet::decrement ( unsigned seqNumber ) +{ + bool signalNeeded; + + { + epicsAutoMutex locker ( this->mutex ); + if ( this->readSeq == seqNumber ) { + if ( this->pndrecvcnt > 0u ) { + this->pndrecvcnt--; + if ( this->pndrecvcnt == 0u ) { + signalNeeded = true; + } + else { + signalNeeded = false; + } + } + else { + signalNeeded = true; + } + } + else { + signalNeeded = false; + } + } + + if ( signalNeeded ) { + this->ioDone.signal (); + } +} + +void ioCounterNet::show ( unsigned level ) const +{ + printf ( "ioCounterNet at %p\n", + static_cast ( this ) ); + printf ( "\tthere are %u unsatisfied IO operations blocking ca_pend_io()\n", + this->pndrecvcnt ); + if ( level > 0u ) { + printf ( "\tthe current read sequence number is %u\n", + this->readSeq ); + } + if ( level > 1u ) { + printf ( "IO done event:\n"); + this->ioDone.show ( level - 2u ); + } +}