From 167abdb5b3fa6900edd6bbdb1cc7d586896a268c Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Fri, 25 Jan 2008 10:45:25 +0000 Subject: restructured queue shutdown so that the queue timeout is properly applied before terminatiing the queue --- srUtils.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'srUtils.c') diff --git a/srUtils.c b/srUtils.c index 590e7eff..4c64ce89 100755 --- a/srUtils.c +++ b/srUtils.c @@ -316,7 +316,7 @@ int getNumberDigits(long lNum) * rgerhards, 2008-01-14 */ rsRetVal -timeoutComp(struct timespec *pt, int iTimeout) +timeoutComp(struct timespec *pt, long iTimeout) { assert(pt != NULL); /* compute timeout */ @@ -331,6 +331,38 @@ timeoutComp(struct timespec *pt, int iTimeout) } +/* This function is kind of the reverse of timeoutComp() - it takes an absolute + * timeout value and computes how far this is in the future. If the value is already + * in the past, 0 is returned. The return value is in ms. + * rgerhards, 2008-01-25 + */ +long +timeoutVal(struct timespec *pt) +{ + struct timespec t; + long iTimeout; + + assert(pt != NULL); + /* compute timeout */ + clock_gettime(CLOCK_REALTIME, &t); + if(pt->tv_sec < t.tv_sec) { + iTimeout = 0; /* in the past! */ + } else if(pt->tv_sec == t.tv_sec) { + if(pt->tv_nsec < t.tv_nsec) { + iTimeout = 0; /* in the past! */ + } else { + iTimeout = (pt->tv_nsec - t.tv_nsec) / 1000; + } + } else { + iTimeout = pt->tv_sec - t.tv_nsec; + iTimeout += 1000 - (pt->tv_nsec / 1000); + iTimeout += t.tv_nsec / 1000; + } + + return iTimeout; +} + + /* cancellation cleanup handler - frees provided mutex * rgerhards, 2008-01-14 */ -- cgit