From ed95f3aaaf0367fe544eb493189aee2b0a355a1b Mon Sep 17 00:00:00 2001 From: Ferdi Franceschini Date: Sat, 2 Mar 2013 16:31:38 +1100 Subject: [PATCH] SICS-555: ANSTO hmcontrol now releases locks on the counters after pausing. --- site_ansto/hmcontrol_ansto.c | 41 ++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/site_ansto/hmcontrol_ansto.c b/site_ansto/hmcontrol_ansto.c index 98c01ada..726cf37a 100644 --- a/site_ansto/hmcontrol_ansto.c +++ b/site_ansto/hmcontrol_ansto.c @@ -22,6 +22,33 @@ /*----------------------------------------------------------------------*/ extern int ANSTO_HTTP_PAUSE; + +typedef struct { + void *slaveData[MAXSLAVE]; + pICountable slaves[MAXSLAVE]; + char *transferScript; + int nSlaves; +} MultiCounter, *pMultiCounter; + +/* Release locks on the multicounter and its slaves */ +static int releaseMCntrLocks(void *pData) { + int i, retVal = OKOK; + pCounter pCount = NULL; + pMultiCounter self = NULL; + + pCount = (pCounter) pData; + if (pCount != NULL) { + self = (pMultiCounter) pCount->pDriv->pData; + } + assert(self); + + for (i = 0; i < self->nSlaves; i++) { + ReleaseCountLock(self->slaves[i]); + } + ReleaseCountLock(pCount->pCountInt); + return retVal; +} + static int HMCStatus_ANSTO(void *pData, SConnection *pCon) // A slightly modified version of the original HMCStatus(), // to support pause-on-count-terminate option for ANSTO HM, @@ -50,9 +77,19 @@ static int HMCStatus_ANSTO(void *pData, SConnection *pCon) // we need to call AnstoHttpPause() via the histmem Pause if (((pHMcontrol_ANSTO)pData)->Pause_HM_After_Count==1) { ANSTO_HTTP_PAUSE = 1; - self->pCount->Pause(self,pCon); + /* ffr: M.K. Introduced counter locking so we must release locks on the + * beam monitor multicounter (ie slave[0]) as well as the hmc controller. + * The lock on hmm gets released by histmem.c:HistCountStatus() because + * anstohttp.c:AnstoHttpStatus() returns HWIdle when the histogram server + * returns "Paused". + * NOTE: The multicounter must be slave 0 since we have already assumed + * that slaves >= 1 are histogram memories (see Warning below). + */ + self->pCount->Pause(self,pCon); + releaseMCntrLocks(self->slaveData[0]); + ReleaseCountLock(self->pCount); // Release hmc } else - self->pCount->Halt(self); + self->pCount->Halt(self); } /* Warning: this assumes that slaves 1 - MAXSLAVE are histogram memories.