This is Unofficial EPICS BASE Doxygen Site
syncGroupReadNotify.cpp
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2002 The University of Chicago, as Operator of Argonne
3 * National Laboratory.
4 * Copyright (c) 2002 The Regents of the University of California, as
5 * Operator of Los Alamos National Laboratory.
6 * EPICS BASE is distributed subject to a Software License Agreement found
7 * in file LICENSE that is included with this distribution.
8 \*************************************************************************/
9 
10 /*
11  * Author: Jeffrey O. Hill
12  * hill@luke.lanl.gov
13  * (505) 665 1831
14  */
15 
16 #include <string>
17 #include <stdexcept>
18 
19 #define epicsAssertAuthor "Jeff Hill johill@lanl.gov"
20 
21 #include "errlog.h"
22 
23 #include "iocinf.h"
24 #include "syncGroup.h"
25 #include "oldAccess.h"
26 
28  CASG & sgIn, PRecycleFunc pRecycleFuncIn,
29  chid pChan, void * pValueIn ) :
30  chan ( pChan ), pRecycleFunc ( pRecycleFuncIn ),
31  sg ( sgIn ), pValue ( pValueIn ),
32  magic ( CASG_MAGIC ), id ( 0u ),
33  idIsValid ( false ), ioComplete ( false )
34 {
35 }
36 
39  unsigned type, arrayElementCount count )
40 {
41  this->chan->eliminateExcessiveSendBacklog ( guard );
42  this->ioComplete = false;
43  boolFlagManager mgr ( this->idIsValid );
44  this->chan->read ( guard, type, count, *this, &this->id );
45  mgr.release ();
46 }
47 
49  CallbackGuard & callbackGuard,
50  epicsGuard < epicsMutex > & mutualExcusionGuard )
51 {
52  if ( this->idIsValid ) {
53  this->chan->ioCancel ( callbackGuard, mutualExcusionGuard, this->id );
54  this->idIsValid = false;
55  }
56 }
57 
60  struct CASG & sg, PRecycleFunc pRecycleFunc, chid chan, void * pValueIn )
61 {
62  return new ( freeList )
63  syncGroupReadNotify ( sg, pRecycleFunc, chan, pValueIn );
64 }
65 
67  CallbackGuard &,
69 {
70  CASG & sgRef ( this->sg );
71  this->~syncGroupReadNotify ();
72  ( sgRef.*pRecycleFunc ) ( guard, *this );
73 }
74 
76 {
77  assert ( ! this->idIsValid );
78 }
79 
81  epicsGuard < epicsMutex > & guard, unsigned type,
82  arrayElementCount count, const void * pData )
83 {
84  if ( this->magic != CASG_MAGIC ) {
85  this->sg.printFormated (
86  "cac: sync group io_complete(): bad sync grp op magic number?\n" );
87  return;
88  }
89 
90  if ( this->pValue ) {
91  size_t size = dbr_size_n ( type, count );
92  memcpy ( this->pValue, pData, size );
93  }
94  this->sg.completionNotify ( guard, *this );
95  this->idIsValid = false;
96  this->ioComplete = true;
97 }
98 
99 void syncGroupReadNotify::exception (
100  epicsGuard < epicsMutex > & guard, int status, const char * pContext,
101  unsigned type, arrayElementCount count )
102 {
103  if ( this->magic != CASG_MAGIC ) {
104  this->sg.printFormated (
105  "cac: sync group io_complete(): bad sync grp op magic number?\n" );
106  return;
107  }
108  this->idIsValid = false;
109  this->sg.exception ( guard, status, pContext,
110  __FILE__, __LINE__, *this->chan, type, count, CA_OP_GET );
111  //
112  // This notify is left installed at this point as a place holder indicating that
113  // all requests have not been completed. This notify is not uninstalled until
114  // CASG::block() times out or unit they call CASG::reset().
115  //
116 }
117 
119  epicsGuard < epicsMutex > &, unsigned level ) const
120 {
121  ::printf ( "pending sg read op: pVal=%p\n", this->pValue );
122  if ( level > 0u ) {
123  ::printf ( "pending sg op: magic=%u sg=%p\n",
124  this->magic, static_cast < void * > ( & this->sg ) );
125  }
126 }
127 
128 void syncGroupReadNotify::operator delete ( void * )
129 {
130  // Visual C++ .net appears to require operator delete if
131  // placement operator delete is defined? I smell a ms rat
132  // because if I declare placement new and delete, but
133  // comment out the placement delete definition there are
134  // no undefined symbols.
135  errlogPrintf ( "%s:%d this compiler is confused about placement delete - memory was probably leaked",
136  __FILE__, __LINE__ );
137 }
138 
139 void * syncGroupReadNotify::operator new ( size_t size,
141 {
142  return freeList.allocate ( size );
143 }
144 
145 #if defined ( CXX_PLACEMENT_DELETE )
146 void syncGroupReadNotify::operator delete ( void *pCadaver,
148 {
149  freeList.release ( pCadaver );
150 }
151 #endif
#define CA_OP_GET
Definition: cadef.h:118
#define assert(exp)
Declare that a condition should be true.
Definition: epicsAssert.h:70
static syncGroupReadNotify * factory(tsFreeList< class syncGroupReadNotify, 128, epicsMutexNOOP > &, CASG &, PRecycleFunc, chid, void *pValueIn)
void(CASG::* PRecycleFunc)(epicsGuard< epicsMutex > &, syncGroupReadNotify &)
Definition: syncGroup.h:64
#define printf
Definition: epicsStdio.h:41
void release()
Definition: syncGroup.h:239
syncGroupReadNotify(CASG &sgIn, PRecycleFunc, chid, void *pValueIn)
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105
void cancel(CallbackGuard &cbGuard, epicsGuard< epicsMutex > &guard)
unsigned long arrayElementCount
Definition: cacIO.h:57
virtual void completion(epicsGuard< epicsMutex > &, unsigned type, arrayElementCount count, const void *pData)=0
void ioCancel(CallbackGuard &callbackGuard, epicsGuard< epicsMutex > &mutualExclusionGuard, const cacChannel::ioid &)
Definition: oldAccess.h:453
#define dbr_size_n(TYPE, COUNT)
Definition: db_access.h:518
void destroy(CallbackGuard &cbGuard, epicsGuard< epicsMutex > &guard)
int printFormated(const char *pFormat,...)
Definition: CASG.cpp:258
void completionNotify(epicsGuard< epicsMutex > &, syncGroupNotify &)
Definition: CASG.cpp:233
void begin(epicsGuard< epicsMutex > &, unsigned type, arrayElementCount count)
void eliminateExcessiveSendBacklog(epicsGuard< epicsMutex > &)
Definition: oldAccess.h:468
#define false
Definition: flexdef.h:85
void show(epicsGuard< epicsMutex > &, unsigned level) const
void read(epicsGuard< epicsMutex > &, unsigned type, arrayElementCount count, cacReadNotify &notify, cacChannel::ioid *pId=0)