diff options
-rw-r--r-- | ChangeLog | 18 | ||||
-rw-r--r-- | misc.c | 25 | ||||
-rw-r--r-- | private.c | 25 | ||||
-rw-r--r-- | pthread.h | 8 |
4 files changed, 60 insertions, 16 deletions
@@ -1,3 +1,21 @@ +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> + Sun Jan 17 12:01:26 1999 Ross Johnson <rpj@ixobrychus.canberra.edu.au> * private.c (_pthread_sem_timedwait): Move from semaphore.c. @@ -129,8 +129,8 @@ pthread_equal (pthread_t t1, pthread_t t2) } /* pthread_equal */ -int -pthreadCancelableWait (HANDLE waitHandle, DWORD abstime) +static int +CancelableWait (HANDLE waitHandle, DWORD timeout) /* * ------------------------------------------------------------------- * This provides an extra hook into the pthread_cancel @@ -151,7 +151,6 @@ pthreadCancelableWait (HANDLE waitHandle, DWORD abstime) DWORD nHandles = 1; DWORD status; - handles[0] = waitHandle; if ((self = pthread_getspecific (_pthread_selfThreadKey)) != NULL) @@ -177,7 +176,7 @@ pthreadCancelableWait (HANDLE waitHandle, DWORD abstime) nHandles, handles, FALSE, - abstime); + timeout); if (status == WAIT_FAILED) @@ -185,10 +184,13 @@ pthreadCancelableWait (HANDLE waitHandle, DWORD abstime) result = EINVAL; } - else if (status == WAIT_ABANDONED_0) + else if (status == WAIT_TIMEOUT) { result = ETIMEDOUT; - + } + else if (status == WAIT_ABANDONED_0) + { + result = EINVAL; } else { @@ -243,6 +245,17 @@ pthreadCancelableWait (HANDLE waitHandle, DWORD abstime) } /* pthreadCancelableWait */ +int +pthreadCancelableWait (HANDLE waitHandle) +{ + return (CancelableWait(waitHandle, INFINITE)); +} + +int +pthreadCancelableTimedWait (HANDLE waitHandle, DWORD timeout) +{ + return (CancelableWait(waitHandle, timeout)); +} /* </JEB> */ @@ -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 */ @@ -918,10 +918,12 @@ int pthread_attr_setschedparam (pthread_attr_t *attr, * WaitForMultipleObjects * * on 'waitHandle' and a manually reset WIN32 Event - * used to implement pthread_cancel. The 'abstime' - * argument is simply passed to WaitForMultipleObjects. + * used to implement pthread_cancel. The 'timeout' + * argument to TimedWait is simply passed to + * WaitForMultipleObjects. */ -int pthreadCancelableWait (HANDLE waitHandle, DWORD abstime); +int pthreadCancelableWait (HANDLE waitHandle); +int pthreadCancelableTimedWait (HANDLE waitHandle, DWORD timeout); /* * Thread-Safe C Runtime Library Mappings |