Skip to content

Commit

Permalink
asTrap serverSpecific is dbChannel
Browse files Browse the repository at this point in the history
Now that asTrapWrite is in dbCore, can save/restore
dbAddr::pfield to avoid corruption by callbacks
  • Loading branch information
mdavidsaver committed Jun 11, 2024
1 parent 0756507 commit 1ba6564
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
14 changes: 11 additions & 3 deletions modules/database/src/ioc/as/asTrapWrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

#include "ellLib.h"
#include "freeList.h"
#include "epicsStdio.h"
#include "cantProceed.h"
#include "epicsMutex.h"
#include "ellLib.h"
#include <dbChannel.h>

#include "asLib.h"
#include "asTrapWrite.h"
Expand Down Expand Up @@ -112,11 +112,12 @@ void epicsStdCall asTrapWriteUnregisterListener(asTrapWriteId id)
}

void * epicsStdCall asTrapWriteBeforeWithData(
const char *userid, const char *hostid, void *addr,
const char *userid, const char *hostid, dbChannel *chan,
int dbrType, int no_elements, void *data)
{
writeMessage *pwriteMessage;
listener *plistener;
void *pfieldsave;

if (pasTrapWritePvt == 0 ||
ellCount(&pasTrapWritePvt->listenerList) <= 0) return 0;
Expand All @@ -125,13 +126,14 @@ void * epicsStdCall asTrapWriteBeforeWithData(
pasTrapWritePvt->freeListWriteMessage);
pwriteMessage->message.userid = userid;
pwriteMessage->message.hostid = hostid;
pwriteMessage->message.serverSpecific = addr;
pwriteMessage->message.serverSpecific = chan;
pwriteMessage->message.dbrType = dbrType;
pwriteMessage->message.no_elements = no_elements;
pwriteMessage->message.data = data;
ellInit(&pwriteMessage->listenerPvtList);

epicsMutexMustLock(pasTrapWritePvt->lock);
pfieldsave = chan->addr.pfield;
ellAdd(&pasTrapWritePvt->writeMessageList, &pwriteMessage->node);
plistener = (listener *)ellFirst(&pasTrapWritePvt->listenerList);
while (plistener) {
Expand All @@ -141,6 +143,7 @@ void * epicsStdCall asTrapWriteBeforeWithData(
plistenerPvt->plistener = plistener;
pwriteMessage->message.userPvt = 0;
plistener->func(&pwriteMessage->message, 0);
chan->addr.pfield = pfieldsave;
plistenerPvt->userPvt = pwriteMessage->message.userPvt;
ellAdd(&pwriteMessage->listenerPvtList, &plistenerPvt->node);
plistener = (listener *)ellNext(&plistener->node);
Expand All @@ -153,18 +156,23 @@ void epicsStdCall asTrapWriteAfterWrite(void *pvt)
{
writeMessage *pwriteMessage = (writeMessage *)pvt;
listenerPvt *plistenerPvt;
dbChannel *chan;
void *pfieldsave;

if (pwriteMessage == 0 ||
pasTrapWritePvt == 0) return;

epicsMutexMustLock(pasTrapWritePvt->lock);
chan = pwriteMessage->message.serverSpecific;
pfieldsave = chan->addr.pfield;
plistenerPvt = (listenerPvt *)ellFirst(&pwriteMessage->listenerPvtList);
while (plistenerPvt) {
listenerPvt *pnext = (listenerPvt *)ellNext(&plistenerPvt->node);
listener *plistener = plistenerPvt->plistener;

pwriteMessage->message.userPvt = plistenerPvt->userPvt;
plistener->func(&pwriteMessage->message, 1);
chan->addr.pfield = pfieldsave;
ellDelete(&pwriteMessage->listenerPvtList, &plistenerPvt->node);
freeListFree(pasTrapWritePvt->freeListListenerPvt, plistenerPvt);
plistenerPvt = pnext;
Expand Down
6 changes: 4 additions & 2 deletions modules/database/src/ioc/as/asTrapWrite.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
extern "C" {
#endif

struct dbChannel;

/**
* \brief The message passed to registered listeners.
*/
Expand All @@ -39,7 +41,7 @@ typedef struct asTrapWriteMessage {
* the value the server provides to asTrapWriteWithData(), which
* for RSRV is the dbChannel pointer for the target field.
*/
void *serverSpecific;
struct dbChannel *serverSpecific;
/** \brief A field for use by the \ref asTrapWriteListener.
*
* When the listener is called before the write, this has the
Expand Down Expand Up @@ -92,7 +94,7 @@ void epicsStdCall asTrapWriteUnregisterListener(

DBCORE_API
void * epicsStdCall asTrapWriteBeforeWithData(
const char *userid, const char *hostid, void *addr,
const char *userid, const char *hostid, struct dbChannel *addr,
int dbrType, int no_elements, void *data);

DBCORE_API
Expand Down

0 comments on commit 1ba6564

Please sign in to comment.