From 292bbca26be928ce109396dc1e03ab8358f1db57 Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Thu, 21 Nov 1996 22:54:00 +0000 Subject: [PATCH] fixed 2 day delay to CPU consumption bugseq_task.c --- src/sequencer/seq_task.c | 71 +++++++++++++++++++++++++++++++--------- 1 file changed, 55 insertions(+), 16 deletions(-) diff --git a/src/sequencer/seq_task.c b/src/sequencer/seq_task.c index 2417b3fa0..715f26de4 100644 --- a/src/sequencer/seq_task.c +++ b/src/sequencer/seq_task.c @@ -29,6 +29,9 @@ 20jul95,ajk Add user-specified task priority to taskSpwan(). ***************************************************************************/ /*#define DEBUG*/ + +#include + #define ANSI #include "seqCom.h" #include "seq.h" @@ -41,13 +44,11 @@ LOCAL VOID seq_waitConnect(SPROG *pSP, SSCB *pSS); LOCAL VOID ss_task_init(SPROG *, SSCB *); LOCAL VOID seq_clearDelay(SSCB *); -LOCAL long seq_getTimeout(SSCB *); +LOCAL int seq_getTimeout(SSCB *); LOCAL long seq_cleanup(int tid, SPROG *pSP, SEM_ID cleanupSem); #define TASK_NAME_SIZE 10 -#define MAX_DELAY (10000000) /* max delay time pending for events */ - STATUS seqAddProg(SPROG *pSP); long seq_connect(SPROG *pSP); @@ -271,19 +272,31 @@ SSCB *pSS; /* * seq_getTimeout() - return time-out for pending on events. * Returns number of tics to next expected timeout of a delay() call. - * Returns MAX_DELAY if no delays pending */ -LOCAL long seq_getTimeout(pSS) + * Returns INT_MAX if no delays pending + * An "int" is returned because this is what semTake() expects + */ +LOCAL int seq_getTimeout(pSS) SSCB *pSS; { - int ndelay; - long delay, delayMin, delayN; + int ndelay, delayMinInit; + ULONG cur, delay, delayMin, delayN; if (pSS->numDelays == 0) - return MAX_DELAY; + return INT_MAX; - delay = tickGet() - pSS->timeEntered; /* actual delay since state entered */ + /* + * calculate the delay since this state was entered + */ + cur = tickGet(); + if (cur>pSS->timeEntered) { + delay = cur - pSS->timeEntered; + } + else { + delay = cur + ULONG_MAX - pSS->timeEntered; + } - delayMin = MAX_DELAY; /* start with largest possible delay */ + delayMinInit = 0; + delayMin = ULONG_MAX; /* Find the minimum delay among all non-expired timeouts */ for (ndelay = 0; ndelay < pSS->numDelays; ndelay++) @@ -297,17 +310,43 @@ SSCB *pSS; pSS->delayExpired[ndelay] = TRUE; /* mark as expired */ return 0; } - else if (delayN < delayMin) - { + + if (delayN<=delayMin) { + delayMinInit=1; delayMin = delayN; /* this is the min. delay so far */ } } - delay = delayMin - delay; - if (delay < 0) - delay = 0; - return delay; + /* + * If there is no unexpired delay in the list + * then wait forever until there is a PV state + * change + */ + if (!delayMinInit) { + return INT_MAX; + } + + /* + * unexpired delay _is_ in the list + */ + if (delayMin>delay) { + delay = delayMin - delay; + + /* + * clip to the range of a valid delay in semTake() + */ + if (delay