diff options
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: |