From c437ef70d78c3600f8b9e700eb9a277742ccb6ff Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Thu, 8 Mar 2007 16:23:57 +1100 Subject: [PATCH] ensure next timer event is in the future for recurrent timers r1614 | dcl | 2007-03-08 16:23:57 +1100 (Thu, 08 Mar 2007) | 2 lines --- nwatch.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/nwatch.c b/nwatch.c index bf57d95d..59e6d0eb 100644 --- a/nwatch.c +++ b/nwatch.c @@ -403,11 +403,23 @@ int NetWatchTask (void* pData) } NetWatchTimerRemQue(self, pNew); iStatus = pNew->func(pNew->cntx, 0); + /* + * If this is a recurrent timer and the function + * indicates to keep it going, put it back in + */ if (pNew->tick && iStatus == 1) { - pNew->tv.tv_usec += 1000 * pNew->tick; - if (pNew->tv.tv_usec > 1000000) { - pNew->tv.tv_sec += pNew->tv.tv_usec / 1000000; - pNew->tv.tv_usec %= 1000000; + /* + * While the expiration time is in the past, increment + */ + gettimeofday(&tv, NULL); + while (tv.tv_sec > pNew->tv.tv_sec || + (tv.tv_sec == pNew->tv.tv_sec && + tv.tv_usec > pNew->tv.tv_usec)) { + pNew->tv.tv_usec += 1000 * pNew->tick; + if (pNew->tv.tv_usec > 1000000) { + pNew->tv.tv_sec += pNew->tv.tv_usec / 1000000; + pNew->tv.tv_usec %= 1000000; + } } NetWatchTimerInsQue(self, pNew); }