pva2pva 1.4.2
Loading...
Searching...
No Matches
MonitorCacheEntry Struct Reference
Inheritance diagram for MonitorCacheEntry:
Collaboration diagram for MonitorCacheEntry:

Public Types

typedef std::vector< epicsUInt8 > pvrequest_t
typedef weak_set< MonitorUser > interested_t

Public Member Functions

 POINTER_DEFINITIONS (MonitorCacheEntry)
epicsMutex & mutex () const
 MonitorCacheEntry (ChannelCacheEntry *ent, const epics::pvData::PVStructure::shared_pointer &pvr)
virtual void monitorConnect (epics::pvData::Status const &status, epics::pvData::MonitorPtr const &monitor, epics::pvData::StructureConstPtr const &structure)
virtual void monitorEvent (epics::pvData::MonitorPtr const &monitor)
virtual void unlisten (epics::pvData::MonitorPtr const &monitor)
virtual std::string getRequesterName ()

Public Attributes

weak_pointer weakref
ChannelCacheEntry *const chan
const size_t bufferSize
bool havedata
bool done
size_t nwakeups
size_t nevents
epics::pvData::StructureConstPtr typedesc
epics::pvData::MonitorElement::shared_pointer lastelem
epics::pvData::MonitorPtr mon
epics::pvData::Status startresult
interested_t interested

Static Public Attributes

static size_t num_instances

Detailed Description

Definition at line 22 of file chancache.h.

Member Typedef Documentation

◆ interested_t

typedef weak_set<MonitorUser> MonitorCacheEntry::interested_t

Definition at line 50 of file chancache.h.

◆ pvrequest_t

typedef std::vector<epicsUInt8> MonitorCacheEntry::pvrequest_t

Definition at line 35 of file chancache.h.

Constructor & Destructor Documentation

◆ MonitorCacheEntry()

MonitorCacheEntry::MonitorCacheEntry ( ChannelCacheEntry * ent,
const epics::pvData::PVStructure::shared_pointer & pvr )

Definition at line 34 of file moncache.cpp.

35 :chan(ent)
36 ,bufferSize(getS<pvd::uint32>(pvr, "record._options.queueSize", 2)) // should be same default as pvAccess, but not required
37 ,havedata(false)
38 ,done(false)
39 ,nwakeups(0)
40 ,nevents(0)
41{
42 epicsAtomicIncrSizeT(&num_instances);
43}

◆ ~MonitorCacheEntry()

MonitorCacheEntry::~MonitorCacheEntry ( )
virtual

Definition at line 45 of file moncache.cpp.

46{
47 pvd::Monitor::shared_pointer M;
48 M.swap(mon);
49 if(M) {
50 M->destroy();
51 }
52 epicsAtomicDecrSizeT(&num_instances);
53 const_cast<ChannelCacheEntry*&>(chan) = NULL; // spoil to fault use after free
54}

Member Function Documentation

◆ getRequesterName()

std::string MonitorCacheEntry::getRequesterName ( )
virtual

Definition at line 244 of file moncache.cpp.

245{
246 return "MonitorCacheEntry";
247}

◆ monitorConnect()

void MonitorCacheEntry::monitorConnect ( epics::pvData::Status const & status,
epics::pvData::MonitorPtr const & monitor,
epics::pvData::StructureConstPtr const & structure )
virtual

Definition at line 57 of file moncache.cpp.

60{
61 interested_t::vector_type tonotify;
62 {
63 Guard G(mutex());
64 if(typedesc) {
65 // we shouldn't have to deal with monitor type change since we
66 // destroy() Monitors on Channel disconnect.
67 std::cerr<<"monitorConnect() w/ new type. Monitor has outlived it's connection.\n";
68 monitor->stop();
69 //TODO: unlisten()
70 return;
71 }
72 typedesc = structure;
73
74 if(status.isSuccess()) {
75 startresult = monitor->start();
76 } else {
77 startresult = status;
78 }
79
80 if(startresult.isSuccess()) {
81 lastelem.reset(new pvd::MonitorElement(pvd::getPVDataCreate()->createPVStructure(structure)));
82 }
83
84 // set typedesc and startresult for futured MonitorUsers
85 // and copy snapshot of already interested MonitorUsers
86 tonotify = interested.lock_vector();
87 }
88
89 if(!startresult.isSuccess())
90 std::cout<<"upstream monitor start() fails\n";
91
92 shared_pointer self(weakref); // keeps us alive all MonitorUsers are destroy()ed
93
94 for(interested_t::vector_type::const_iterator it = tonotify.begin(),
95 end = tonotify.end(); it!=end; ++it)
96 {
97 pvd::MonitorRequester::shared_pointer req((*it)->req);
98 if(req) {
99 req->monitorConnect(startresult, *it, structure);
100 }
101 }
102}
epics::pvData::MonitorElement::shared_pointer lastelem
Definition chancache.h:46

◆ monitorEvent()

void MonitorCacheEntry::monitorEvent ( epics::pvData::MonitorPtr const & monitor)
virtual

Definition at line 110 of file moncache.cpp.

111{
112 /* PVA is being tricky, the Monitor* passed to monitorConnect()
113 * isn't the same one we see here!
114 * The original was a ChannelMonitorImpl, we now see a MonitorStrategyQueue
115 * owned by the original, which delegates deserialization and accumulation
116 * of deltas into complete events for us.
117 * However, we don't want to keep the MonitorStrategyQueue as it's
118 * destroy() method is a no-op!
119 */
120
121 epicsAtomicIncrSizeT(&nwakeups);
122
123 shared_pointer self(weakref); // keeps us alive in case all MonitorUsers are destroy()ed
124
125 pva::MonitorElementPtr update;
126
127 typedef std::vector<MonitorUser::shared_pointer> dsnotify_t;
128 dsnotify_t dsnotify;
129
130 {
131 Guard G(mutex()); // MCE and MU guarded by the same mutex
132 if(!havedata)
133 havedata = true;
134
135 //TODO: flow control, if all MU buffers are full, break before poll()==NULL
136 while((update=monitor->poll()))
137 {
138 epicsAtomicIncrSizeT(&nevents);
139
140 lastelem->pvStructurePtr->copyUnchecked(*update->pvStructurePtr,
141 *update->changedBitSet);
142 *lastelem->changedBitSet = *update->changedBitSet;
143 *lastelem->overrunBitSet = *update->overrunBitSet;
144 monitor->release(update);
145 update.reset();
146
147 interested_t::iterator IIT(interested); // recursively locks interested.mutex() (assumes this->mutex() is interestd.mutex())
148 for(interested_t::value_pointer pusr = IIT.next(); pusr; pusr = IIT.next())
149 {
150 MonitorUser *usr = pusr.get();
151
152 {
153 Guard G(usr->mutex());
154 if(usr->initial)
155 continue; // no start() yet
156 // TODO: track overflow when !running (after stop())?
157 if(!usr->running || usr->empty.empty()) {
158 usr->inoverflow = true;
159
160 /* overrun |= lastelem->overrun // upstream overflows
161 * overrun |= changed & lastelem->changed // downstream overflows
162 * changed |= lastelem->changed // accumulate changes
163 */
164
165 *usr->overflowElement->overrunBitSet |= *lastelem->overrunBitSet;
166 usr->overflowElement->overrunBitSet->or_and(*usr->overflowElement->changedBitSet,
167 *lastelem->changedBitSet);
168 *usr->overflowElement->changedBitSet |= *lastelem->changedBitSet;
169
170 usr->overflowElement->pvStructurePtr->copyUnchecked(*lastelem->pvStructurePtr,
171 *lastelem->changedBitSet);
172
173 epicsAtomicIncrSizeT(&usr->ndropped);
174 continue;
175 }
176 // we only come out of overflow when downstream release()s an element to us
177 // empty.empty() does not imply inoverflow,
178 // however inoverflow does imply empty.empty()
179 assert(!usr->inoverflow);
180
181 if(usr->filled.empty())
182 dsnotify.push_back(pusr);
183
184 pvd::MonitorElementPtr elem(usr->empty.front());
185
186 *elem->overrunBitSet = *lastelem->overrunBitSet;
187 *elem->changedBitSet = *lastelem->changedBitSet;
188 // Note: can't use changed mask to optimize this copy since we don't know
189 // the state of the free element
190 elem->pvStructurePtr->copyUnchecked(*lastelem->pvStructurePtr);
191
192 usr->filled.push_back(elem);
193 usr->empty.pop_front();
194
195 epicsAtomicIncrSizeT(&usr->nevents);
196 }
197 }
198 }
199 }
200
201 // unlock here, race w/ stop(), unlisten()?
202 //TODO: notify from worker thread
203
204 FOREACH(dsnotify_t::iterator, it,end,dsnotify) {
205 MonitorUser *usr = (*it).get();
206 pvd::MonitorRequester::shared_pointer req(usr->req.lock());
207 if(!req)
208 continue; // downstream requester has already been destroyed
209 epicsAtomicIncrSizeT(&usr->nwakeups);
210 req->monitorEvent(*it); // notify when first item added to empty queue, may call poll(), release(), and others
211 }
212}

◆ mutex()

epicsMutex & MonitorCacheEntry::mutex ( ) const
inline

Definition at line 33 of file chancache.h.

33{ return interested.mutex(); }

◆ unlisten()

void MonitorCacheEntry::unlisten ( epics::pvData::MonitorPtr const & monitor)
virtual

Definition at line 216 of file moncache.cpp.

217{
218 pvd::Monitor::shared_pointer M;
219 interested_t::vector_type tonotify;
220 {
221 Guard G(mutex());
222 M.swap(mon);
223 tonotify = interested.lock_vector();
224 // assume that upstream won't call monitorEvent() again
225
226 // cause future downstream start() to error
227 startresult = pvd::Status(pvd::Status::STATUSTYPE_ERROR, "upstream unlisten()");
228 }
229 if(M) {
230 M->destroy();
231 }
232 FOREACH(interested_t::vector_type::iterator, it, end, tonotify) {
233 MonitorUser *usr = it->get();
234 pvd::MonitorRequester::shared_pointer req(usr->req);
235 Guard G(usr->mutex());
236 if(usr->inuse.empty()) { // TODO: what about stopped?
237 UnGuard U(G);
238 req->unlisten(*it);
239 }
240 }
241}

Member Data Documentation

◆ bufferSize

const size_t MonitorCacheEntry::bufferSize

Definition at line 30 of file chancache.h.

◆ chan

ChannelCacheEntry* const MonitorCacheEntry::chan

Definition at line 28 of file chancache.h.

◆ done

bool MonitorCacheEntry::done

Definition at line 38 of file chancache.h.

◆ havedata

bool MonitorCacheEntry::havedata

Definition at line 37 of file chancache.h.

◆ interested

interested_t MonitorCacheEntry::interested

Definition at line 51 of file chancache.h.

◆ lastelem

epics::pvData::MonitorElement::shared_pointer MonitorCacheEntry::lastelem

value of upstream monitor (accumulation of all deltas) changed/overflow bit masks of last delta

Definition at line 46 of file chancache.h.

◆ mon

epics::pvData::MonitorPtr MonitorCacheEntry::mon

Definition at line 47 of file chancache.h.

◆ nevents

size_t MonitorCacheEntry::nevents

Definition at line 40 of file chancache.h.

◆ num_instances

size_t MonitorCacheEntry::num_instances
static

Definition at line 25 of file chancache.h.

◆ nwakeups

size_t MonitorCacheEntry::nwakeups

Definition at line 39 of file chancache.h.

◆ startresult

epics::pvData::Status MonitorCacheEntry::startresult

Definition at line 48 of file chancache.h.

◆ typedesc

epics::pvData::StructureConstPtr MonitorCacheEntry::typedesc

Definition at line 42 of file chancache.h.

◆ weakref

weak_pointer MonitorCacheEntry::weakref

Definition at line 26 of file chancache.h.


The documentation for this struct was generated from the following files: