diff options
author | rpj <rpj> | 1999-01-18 23:50:07 +0000 |
---|---|---|
committer | rpj <rpj> | 1999-01-18 23:50:07 +0000 |
commit | 20f77eda55f874b939719ac0abda4405ecd20bf8 (patch) | |
tree | e81393914f1a89d055b2384cc1c612d48c4a2a2c /private.c | |
parent | 9b75468a10363ada39a17563cca6bcd819ec8fcd (diff) |
Tue Jan 19 18:27:42 1999 Ross Johnson <rpj@swan.canberra.edu.au>
* 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 <scott@curriculum.com>
Diffstat (limited to 'private.c')
-rw-r--r-- | private.c | 25 |
1 files changed, 18 insertions, 7 deletions
@@ -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 */ |