From 5a14301bbe7dd7f23bfc60f76f66b0880b3241ae Mon Sep 17 00:00:00 2001 From: bje Date: Sun, 19 Jul 1998 13:02:12 +0000 Subject: 1998-07-19 Ben Elliston * condvar.c (pthread_cond_wait): Generalise. Moved from here .. (cond_wait): To here. (pthread_cond_timedwait): Implement; use generalised cond_wait(). --- condvar.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/condvar.c b/condvar.c index e8f858c..addf750 100644 --- a/condvar.c +++ b/condvar.c @@ -63,8 +63,12 @@ pthread_cond_init(pthread_cond_t *cv, const pthread_condattr_t *attr) return 0; } -int -pthread_cond_wait(pthread_cond_t *cv, pthread_mutex_t *mutex) +/* This is an internal routine that allows the functions `pthread_cond_wait' and + `pthread_cond_timedwait' to share implementations. The `abstime' + parameter to this function is in millisecond units (or INFINITE). */ + +static int +cond_wait(pthread_cond_t *cv, pthread_mutex_t *mutex, DWORD abstime) { int result, last_waiter; @@ -89,7 +93,7 @@ pthread_cond_wait(pthread_cond_t *cv, pthread_mutex_t *mutex) pthread_cond_signal() being called or pthread_cond_broadcast() being called. */ - result = WaitForMultipleObjects (2, ev->events, FALSE, INFINITE); + result = WaitForMultipleObjects (2, ev->events, FALSE, abstime); EnterCriticalSection (&cv->waiters_count_lock); cv->waiters_count--; @@ -110,17 +114,30 @@ pthread_cond_wait(pthread_cond_t *cv, pthread_mutex_t *mutex) return 0; } +int +pthread_cond_wait(pthread_cond_t *cv, + pthread_mutex_t *mutex) +{ + return cond_wait(cv, mutex, INFINITE); +} + +/* Assume that our configure script will test for the existence of + `struct timespec' and define it according to POSIX if it isn't + found. This will enable people to use this implementation + without necessarily needing Cygwin32. */ + int pthread_cond_timedwait(pthread_cond_t *cv, pthread_mutex_t *mutex, const struct timespec *abstime) { - /* Yet to be implemented. This will be identical to cond_wait(), - but we will need to get the timeout parameter in the call to - WaitForMultipleObject() as close to the time specified in - `abstime' as possible. */ + DWORD msecs; + + /* Calculate the number of milliseconds in abstime. */ + msecs = abstime->tv_sec * 1000; + msecs += abstime->tv_nsec / 1000000; - return 0; + return cond_wait(cv, mutex, msecs); } int -- cgit v1.2.3