This is Unofficial EPICS BASE Doxygen Site
syncGroupWriteNotify.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  PRecycleFunc pRecycleFuncIn, chid pChan ) :
29  chan ( pChan ), pRecycleFunc ( pRecycleFuncIn ),
30  sg ( sgIn ), magic ( CASG_MAGIC ),
31  id ( 0u ), idIsValid ( false ), ioComplete ( false )
32 {
33 }
34 
36  epicsGuard < epicsMutex > & guard, unsigned type,
37  arrayElementCount count, const void * pValueIn )
38 {
39  this->chan->eliminateExcessiveSendBacklog ( guard );
40  this->ioComplete = false;
41  boolFlagManager mgr ( this->idIsValid );
42  this->chan->write ( guard, type, count,
43  pValueIn, *this, &this->id );
44  mgr.release ();
45 }
46 
48  CallbackGuard & callbackGuard,
49  epicsGuard < epicsMutex > & mutualExcusionGuard )
50 {
51  if ( this->idIsValid ) {
52  this->chan->ioCancel ( callbackGuard, mutualExcusionGuard, this->id );
53  this->idIsValid = false;
54  }
55 }
56 
59  struct CASG & sg, PRecycleFunc pRecycleFunc, chid chan )
60 {
61  return new ( freeList ) syncGroupWriteNotify ( sg, pRecycleFunc, chan );
62 }
63 
65  CallbackGuard &,
67 {
68  CASG & sgRef ( this->sg );
69  this->~syncGroupWriteNotify ();
70  ( sgRef.*pRecycleFunc ) ( guard, *this );
71 }
72 
74 {
75  assert ( ! this->idIsValid );
76 }
77 
80 {
81  if ( this->magic != CASG_MAGIC ) {
82  this->sg.printFormated ( "cac: sync group io_complete(): bad sync grp op magic number?\n" );
83  return;
84  }
85  this->sg.completionNotify ( guard, *this );
86  this->idIsValid = false;
87  this->ioComplete = true;
88 }
89 
90 void syncGroupWriteNotify::exception (
92  int status, const char *pContext, unsigned type, arrayElementCount count )
93 {
94  if ( this->magic != CASG_MAGIC ) {
95  this->sg.printFormated ( "cac: sync group io_complete(): bad sync grp op magic number?\n" );
96  return;
97  }
98  this->sg.exception ( guard, status, pContext,
99  __FILE__, __LINE__, *this->chan, type, count, CA_OP_PUT );
100  this->idIsValid = false;
101  //
102  // This notify is left installed at this point as a place holder indicating that
103  // all requests have not been completed. This notify is not uninstalled until
104  // CASG::block() times out or unit they call CASG::reset().
105  //
106 }
107 
109  epicsGuard < epicsMutex > &, unsigned level ) const
110 {
111  ::printf ( "pending write sg op\n" );
112  if ( level > 0u ) {
113  ::printf ( "pending sg op: magic=%u sg=%p\n",
114  this->magic, static_cast < void * > ( &this->sg ) );
115  }
116 }
117 
118 void syncGroupWriteNotify::operator delete ( void * )
119 {
120  // Visual C++ .net appears to require operator delete if
121  // placement operator delete is defined? I smell a ms rat
122  // because if I declare placement new and delete, but
123  // comment out the placement delete definition there are
124  // no undefined symbols.
125  errlogPrintf ( "%s:%d this compiler is confused about placement delete - memory was probably leaked",
126  __FILE__, __LINE__ );
127 }
128 
129 void * syncGroupWriteNotify::operator new ( size_t size,
131 {
132  return freeList.allocate ( size );
133 }
134 
135 #if defined ( CXX_PLACEMENT_DELETE )
136 void syncGroupWriteNotify::operator delete ( void *pCadaver,
138 {
139  freeList.release ( pCadaver );
140 }
141 #endif
142 
void(CASG::* PRecycleFunc)(epicsGuard< epicsMutex > &, syncGroupWriteNotify &)
Definition: syncGroup.h:109
void cancel(CallbackGuard &cbGuard, epicsGuard< epicsMutex > &guard)
#define assert(exp)
Declare that a condition should be true.
Definition: epicsAssert.h:70
void destroy(CallbackGuard &cbGuard, epicsGuard< epicsMutex > &guard)
#define printf
Definition: epicsStdio.h:41
#define CA_OP_PUT
Definition: cadef.h:119
void release()
Definition: syncGroup.h:239
static syncGroupWriteNotify * factory(tsFreeList< class syncGroupWriteNotify, 128, epicsMutexNOOP > &, CASG &, PRecycleFunc, chid)
void show(epicsGuard< epicsMutex > &, unsigned level) const
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105
unsigned long arrayElementCount
Definition: cacIO.h:57
void ioCancel(CallbackGuard &callbackGuard, epicsGuard< epicsMutex > &mutualExclusionGuard, const cacChannel::ioid &)
Definition: oldAccess.h:453
void write(epicsGuard< epicsMutex > &, unsigned type, arrayElementCount count, const void *pValue, cacWriteNotify &, cacChannel::ioid *pId=0)
int printFormated(const char *pFormat,...)
Definition: CASG.cpp:258
void completionNotify(epicsGuard< epicsMutex > &, syncGroupNotify &)
Definition: CASG.cpp:233
virtual void completion(epicsGuard< epicsMutex > &)=0
void eliminateExcessiveSendBacklog(epicsGuard< epicsMutex > &)
Definition: oldAccess.h:468
void begin(epicsGuard< epicsMutex > &, unsigned type, arrayElementCount count, const void *pValueIn)
syncGroupWriteNotify(struct CASG &, PRecycleFunc, chid)
#define false
Definition: flexdef.h:85