From b14e60afab45a7bc5eff231f408505a1bec6b436 Mon Sep 17 00:00:00 2001 From: rpj Date: Thu, 11 Mar 1999 15:06:20 +0000 Subject: Thu Mar 11 09:01:48 1999 Ross Johnson * pthread.h (pthread_mutex_t): revert to (pthread_mutex_t *); define a value to serve as PTHREAD_MUTEX_INITIALIZER. (pthread_mutex_t_): remove staticinit and valid elements. (pthread_cond_t): revert to (pthread_cond_t_ *); define a value to serve as PTHREAD_COND_INITIALIZER. (pthread_cond_t_): remove staticinit and valid elements. * mutex.c (pthread_mutex_t args): adjust indirection of references. (all functions): check for PTHREAD_MUTEX_INITIALIZER value; check for NULL (invalid). * condvar.c (pthread_cond_t args): adjust indirection of references. (all functions): check for PTHREAD_COND_INITIALIZER value; check for NULL (invalid). Wed Mar 10 17:18:12 1999 Ross Johnson * misc.c (CancelableWait): Undo changes from Mar 8 and 7. tests/ChangeLog Fri Mar 12 08:34:15 1999 Ross Johnson * eyal1.c (main): Fix trylock loop; was not waiting for thread to lock the "started" mutex. --- misc.c | 52 ++++++++++++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 28 deletions(-) (limited to 'misc.c') diff --git a/misc.c b/misc.c index df7af10..b5cbecf 100644 --- a/misc.c +++ b/misc.c @@ -213,12 +213,8 @@ CancelableWait (HANDLE waitHandle, DWORD timeout) DWORD nHandles = 1; DWORD status; - /* - * If both objects are signaled, then (status - WAIT_OBJECT_0) - * will be the lowest index value of all the signaled objects. - * We must ensure that a cancelation is recognised if this occurs by - * placing the cancelEvent handle first in the handle table. - */ + handles[0] = waitHandle; + if ((self = (pthread_t) pthread_getspecific (_pthread_selfThreadKey)) != NULL) { @@ -228,14 +224,16 @@ CancelableWait (HANDLE waitHandle, DWORD timeout) if (self->cancelState == PTHREAD_CANCEL_ENABLE) { - if ((handles[0] = self->cancelEvent) != NULL) + if ((handles[1] = self->cancelEvent) != NULL) { nHandles++; } } } - - handles[nHandles - 1] = waitHandle; + else + { + handles[1] = NULL; + } status = WaitForMultipleObjects ( nHandles, @@ -243,36 +241,41 @@ CancelableWait (HANDLE waitHandle, DWORD timeout) FALSE, timeout); + if (status == WAIT_FAILED) { result = EINVAL; + } else if (status == WAIT_TIMEOUT) { result = ETIMEDOUT; } - else if (status >= WAIT_ABANDONED_0 && status <= WAIT_ABANDONED_0 + nHandles - 1) + else if (status == WAIT_ABANDONED_0) { - /* - * The waitHandle was a mutex object that was abandoned. - */ result = EINVAL; } else { /* - * Either got the object or the cancel event - * was signaled, or both in which case the cancel - * event will be acted on. + * Either got the mutex or the cancel event + * was signaled */ - switch (status - WAIT_OBJECT_0 + 2 - nHandles) + switch (status - WAIT_OBJECT_0) { case 0: /* - * Got cancel request. + * Got the mutex + */ + result = 0; + break; + + case 1: + /* + * Got cancel request */ - ResetEvent (handles[0]); + ResetEvent (handles[1]); if (self != NULL && !self->implicit) { @@ -304,15 +307,8 @@ CancelableWait (HANDLE waitHandle, DWORD timeout) #endif /* _MSC_VER */ } - /* Should never get to here. */ - result = EINVAL; - break; - - case 1: - /* - * Got the object. - */ - result = 0; + /* Should never get to here. */ + result = EINVAL; break; default: -- cgit v1.2.3