diff options
author | rpj <rpj> | 1999-03-11 15:06:20 +0000 |
---|---|---|
committer | rpj <rpj> | 1999-03-11 15:06:20 +0000 |
commit | b14e60afab45a7bc5eff231f408505a1bec6b436 (patch) | |
tree | 4f9980eea7b03957476af05736a2c8364027d9c3 /misc.c | |
parent | 52f7c3f5ef6d9b70ec385fb390bf27962e68ee3d (diff) |
Thu Mar 11 09:01:48 1999 Ross Johnson <rpj@ixobrychus.canberra.edu.au>
* 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 <rpj@ixobrychus.canberra.edu.au>
* misc.c (CancelableWait): Undo changes from Mar 8 and 7.
tests/ChangeLog
Fri Mar 12 08:34:15 1999 Ross Johnson <rpj@ixobrychus.canberra.edu.au>
* eyal1.c (main): Fix trylock loop; was not waiting for thread to lock
the "started" mutex.
Diffstat (limited to 'misc.c')
-rw-r--r-- | misc.c | 52 |
1 files changed, 24 insertions, 28 deletions
@@ -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: |