From bbd94928bbed65959b1b2ed72cea14cd3c2d4806 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Wed, 26 Apr 2017 15:59:03 -0500 Subject: [PATCH] Minimize work done in readLocked() routine Move post-I/O work back to the read_xx routines. --- src/std/dev/devAiSoft.c | 50 ++++++++++++++++++++---------------- src/std/dev/devMbbiSoftRaw.c | 18 ++++++++----- src/std/dev/devSiSoft.c | 17 +++++++----- src/std/dev/devWfSoft.c | 35 ++++++++++++++++--------- 4 files changed, 72 insertions(+), 48 deletions(-) diff --git a/src/std/dev/devAiSoft.c b/src/std/dev/devAiSoft.c index 69afff3ee..0ecc1b13f 100644 --- a/src/std/dev/devAiSoft.c +++ b/src/std/dev/devAiSoft.c @@ -56,42 +56,48 @@ static long init_record(aiRecord *prec) return 0; } -static long readLocked(struct link *pinp, void *dummy) -{ - aiRecord *prec = (aiRecord *) pinp->precord; +struct aivt { double val; - long status = dbGetLink(pinp, DBR_DOUBLE, &val, 0, 0); + epicsTimeStamp *ptime; +}; - if (status) return status; +static long readLocked(struct link *pinp, void *vvt) +{ + struct aivt *pvt = (struct aivt *) vvt; + long status = dbGetLink(pinp, DBR_DOUBLE, &pvt->val, 0, 0); - /* Apply smoothing algorithm */ - if (prec->smoo != 0.0 && prec->dpvt && finite(prec->val)) - prec->val = val * (1.00 - prec->smoo) + (prec->val * prec->smoo); - else - prec->val = val; + if (!status && pvt->ptime) + dbGetTimeStamp(pinp, pvt->ptime); - prec->udf = FALSE; - prec->dpvt = &devAiSoft; /* Any non-zero value */ - - if (dbLinkIsConstant(&prec->tsel) && - prec->tse == epicsTimeEventDeviceTime) - dbGetTimeStamp(pinp, &prec->time); - - return 0; + return status; } static long read_ai(aiRecord *prec) { long status; + struct aivt vt; if (dbLinkIsConstant(&prec->inp)) return 2; - status = dbLinkDoLocked(&prec->inp, readLocked, NULL); - if (status == S_db_noLSET) - status = readLocked(&prec->inp, NULL); + vt.ptime = (dbLinkIsConstant(&prec->tsel) && + prec->tse == epicsTimeEventDeviceTime) ? &prec->time : NULL; - if (status) + status = dbLinkDoLocked(&prec->inp, readLocked, &vt); + if (status == S_db_noLSET) + status = readLocked(&prec->inp, &vt); + + if (!status) { + /* Apply smoothing algorithm */ + if (prec->smoo != 0.0 && prec->dpvt && finite(prec->val)) + prec->val = vt.val * (1.0 - prec->smoo) + (prec->val * prec->smoo); + else + prec->val = vt.val; + + prec->udf = FALSE; + prec->dpvt = &devAiSoft; /* Any non-zero value */ + } + else prec->dpvt = NULL; return 2; diff --git a/src/std/dev/devMbbiSoftRaw.c b/src/std/dev/devMbbiSoftRaw.c index fde76513a..3bd6b21da 100644 --- a/src/std/dev/devMbbiSoftRaw.c +++ b/src/std/dev/devMbbiSoftRaw.c @@ -60,14 +60,15 @@ static long init_record(mbbiRecord *prec) static long readLocked(struct link *pinp, void *dummy) { mbbiRecord *prec = (mbbiRecord *) pinp->precord; + long status = dbGetLink(pinp, DBR_LONG, &prec->rval, 0, 0); - if (!dbGetLink(pinp, DBR_LONG, &prec->rval, 0, 0)) { - prec->rval &= prec->mask; - if (dbLinkIsConstant(&prec->tsel) && - prec->tse == epicsTimeEventDeviceTime) - dbGetTimeStamp(pinp, &prec->time); - } - return 0; + if (status) return status; + + if (dbLinkIsConstant(&prec->tsel) && + prec->tse == epicsTimeEventDeviceTime) + dbGetTimeStamp(pinp, &prec->time); + + return status; } static long read_mbbi(mbbiRecord *prec) @@ -77,5 +78,8 @@ static long read_mbbi(mbbiRecord *prec) if (status == S_db_noLSET) status = readLocked(&prec->inp, NULL); + if (!status) + prec->rval &= prec->mask; + return status; } diff --git a/src/std/dev/devSiSoft.c b/src/std/dev/devSiSoft.c index 9b1fcfe4b..5141c1038 100644 --- a/src/std/dev/devSiSoft.c +++ b/src/std/dev/devSiSoft.c @@ -51,6 +51,7 @@ static long init_record(stringinRecord *prec) { if (recGblInitConstantLink(&prec->inp, DBF_STRING, prec->val)) prec->udf = FALSE; + return 0; } @@ -59,13 +60,12 @@ static long readLocked(struct link *pinp, void *dummy) stringinRecord *prec = (stringinRecord *) pinp->precord; long status = dbGetLink(pinp, DBR_STRING, prec->val, 0, 0); - if (!status) { - if (!dbLinkIsConstant(pinp)) - prec->udf = FALSE; - if (dbLinkIsConstant(&prec->tsel) && - prec->tse == epicsTimeEventDeviceTime) - dbGetTimeStamp(pinp, &prec->time); - } + if (status) return status; + + if (dbLinkIsConstant(&prec->tsel) && + prec->tse == epicsTimeEventDeviceTime) + dbGetTimeStamp(pinp, &prec->time); + return status; } @@ -76,5 +76,8 @@ static long read_stringin(stringinRecord *prec) if (status == S_db_noLSET) status = readLocked(&prec->inp, NULL); + if (!status && !dbLinkIsConstant(&prec->inp)) + prec->udf = FALSE; + return status; } diff --git a/src/std/dev/devWfSoft.c b/src/std/dev/devWfSoft.c index d1daefd7b..8d8295696 100644 --- a/src/std/dev/devWfSoft.c +++ b/src/std/dev/devWfSoft.c @@ -60,29 +60,40 @@ static long init_record(waveformRecord *prec) return status; } -static long readLocked(struct link *pinp, void *dummy) +struct wfrt { + long nRequest; + epicsTimeStamp *ptime; +}; + +static long readLocked(struct link *pinp, void *vrt) { waveformRecord *prec = (waveformRecord *) pinp->precord; - long nRequest = prec->nelm; - long status = dbGetLink(pinp, prec->ftvl, prec->bptr, 0, &nRequest); + struct wfrt *prt = (struct wfrt *) vrt; + long status = dbGetLink(pinp, prec->ftvl, prec->bptr, 0, &prt->nRequest); - if (!status && nRequest > 0) { - prec->nord = nRequest; - prec->udf = FALSE; + if (!status && prt->ptime) + dbGetTimeStamp(pinp, prt->ptime); - if (dbLinkIsConstant(&prec->tsel) && - prec->tse == epicsTimeEventDeviceTime) - dbGetTimeStamp(pinp, &prec->time); - } return status; } static long read_wf(waveformRecord *prec) { - long status = dbLinkDoLocked(&prec->inp, readLocked, NULL); + long status; + struct wfrt rt; + rt.nRequest = prec->nelm; + rt.ptime = (dbLinkIsConstant(&prec->tsel) && + prec->tse == epicsTimeEventDeviceTime) ? &prec->time : NULL; + + status = dbLinkDoLocked(&prec->inp, readLocked, &rt); if (status == S_db_noLSET) - status = readLocked(&prec->inp, NULL); + status = readLocked(&prec->inp, &rt); + + if (!status && rt.nRequest > 0) { + prec->nord = rt.nRequest; + prec->udf = FALSE; + } return status; }