From 20f77eda55f874b939719ac0abda4405ecd20bf8 Mon Sep 17 00:00:00 2001 From: rpj Date: Mon, 18 Jan 1999 23:50:07 +0000 Subject: Tue Jan 19 18:27:42 1999 Ross Johnson * pthread.h (pthreadCancelableTimedWait): New prototype. (pthreadCancelableWait): Remove second argument. * misc.c (CancelableWait): New static function is pthreadCancelableWait() renamed. (pthreadCancelableWait): Now just calls CancelableWait() with INFINITE timeout. (pthreadCancelableTimedWait): Just calls CancelableWait() with passed in timeout. * private.c (_pthread_sem_timedwait): 'abstime' arg really is absolute time. Calculate relative time to wait from current time before passing timeout to new routine pthreadCancelableTimedWait(). - Scott Lightner --- private.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'private.c') diff --git a/private.c b/private.c index f20413c..1039d81 100644 --- a/private.c +++ b/private.c @@ -443,8 +443,8 @@ _pthread_sem_timedwait (sem_t * sem, const struct timespec * abstime) /* * ------------------------------------------------------ * DOCPUBLIC - * This function waits on a semaphore for at most - * 'abstime'. + * This function waits on a semaphore possibly until + * 'abstime' time. * * PARAMETERS * sem @@ -476,7 +476,10 @@ _pthread_sem_timedwait (sem_t * sem, const struct timespec * abstime) * ------------------------------------------------------ */ { - DWORD msecs; + struct _timeb currSysTime; + const DWORD NANOSEC_PER_MILLISEC = 1000000; + const DWORD MILLISEC_PER_SEC = 1000; + DWORD milliseconds; if (abstime == NULL) { @@ -484,14 +487,22 @@ _pthread_sem_timedwait (sem_t * sem, const struct timespec * abstime) } else { - /* Calculate the number of milliseconds in abstime. */ - msecs = abstime->tv_sec * 1000; - msecs += abstime->tv_nsec / 1000000; + /* + * Calculate timeout as milliseconds from current system time. + */ + + /* get current system time */ + _ftime(&currSysTime); + + /* subtract current system time from abstime */ + milliseconds = (abstime->tv_sec - currSysTime.time) * MILLISEC_PER_SEC; + milliseconds += (abstime->tv_nsec / NANOSEC_PER_MILLISEC) - + currSysTime.millitm; } return ((sem == NULL) ? EINVAL - : pthreadCancelableWait (*sem, msecs) + : pthreadCancelableTimedWait (*sem, milliseconds) ); } /* _pthread_sem_timedwait */ -- cgit v1.2.3