summaryrefslogtreecommitdiff
path: root/w32_CancelableWait.c
diff options
context:
space:
mode:
authorrpj <rpj>2002-07-30 12:52:52 +0000
committerrpj <rpj>2002-07-30 12:52:52 +0000
commitccd0f86e370fa71acd47c17cb9579877403c81d1 (patch)
tree16ddf8cef155093de95b62cd9d3cd6f522970d45 /w32_CancelableWait.c
parent5c1bda8e72572064653230f4fcbdf0d5df627085 (diff)
* sem_timedwait.c (sem_timedwait): Tighten checks for
unreasonable abstime values - that would result in unexpected timeout values. * w32_CancelableWait.c (ptw32_cancelable_wait): Tighten up return value checking and add comments.
Diffstat (limited to 'w32_CancelableWait.c')
-rw-r--r--w32_CancelableWait.c125
1 files changed, 59 insertions, 66 deletions
diff --git a/w32_CancelableWait.c b/w32_CancelableWait.c
index ba1c92a..2f84743 100644
--- a/w32_CancelableWait.c
+++ b/w32_CancelableWait.c
@@ -68,13 +68,13 @@ ptw32_cancelable_wait (HANDLE waitHandle, DWORD timeout)
* Get cancelEvent handle
*/
if (self->cancelState == PTHREAD_CANCEL_ENABLE)
- {
+ {
- if ((handles[1] = self->cancelEvent) != NULL)
- {
- nHandles++;
- }
- }
+ if ((handles[1] = self->cancelEvent) != NULL)
+ {
+ nHandles++;
+ }
+ }
}
else
{
@@ -88,68 +88,61 @@ ptw32_cancelable_wait (HANDLE waitHandle, DWORD timeout)
timeout);
- if (status == WAIT_FAILED)
- {
- result = EINVAL;
- }
- else if (status == WAIT_TIMEOUT)
- {
- result = ETIMEDOUT;
- }
- else if (status == WAIT_ABANDONED_0)
- {
- result = EINVAL;
- }
- else
- {
- /*
- * Either got the handle or the cancel event
- * was signaled
- */
- switch (status - WAIT_OBJECT_0)
- {
-
- case 0:
- /*
- * Got the handle
- */
- result = 0;
- break;
-
- case 1:
- /*
- * Got cancel request
- */
- ResetEvent (handles[1]);
-
- if (self != NULL && !self->implicit)
- {
- /*
- * Thread started with pthread_create.
- * Make sure we haven't been async-canceled in the meantime.
- */
- (void) pthread_mutex_lock(&self->cancelLock);
- if (self->state < PThreadStateCanceling)
+ switch (status - WAIT_OBJECT_0)
{
- self->state = PThreadStateCanceling;
- self->cancelState = PTHREAD_CANCEL_DISABLE;
- (void) pthread_mutex_unlock(&self->cancelLock);
- ptw32_throw(PTW32_EPS_CANCEL);
-
- /* Never reached */
+ case 0:
+ /*
+ * Got the handle.
+ * In the event that both handles are signalled, the smallest index
+ * value (us) is returned. As it has been arranged, this ensures that
+ * we don't drop a signal that we should act on (i.e. semaphore,
+ * mutex, or condition variable etc).
+ */
+ result = 0;
+ break;
+
+ case 1:
+ /*
+ * Got cancel request.
+ * In the event that both handles are signalled, the cancel will
+ * be ignored (see case 0 comment).
+ */
+ ResetEvent (handles[1]);
+
+ if (self != NULL && !self->implicit)
+ {
+ /*
+ * Thread started with pthread_create.
+ * Make sure we haven't been async-canceled in the meantime.
+ */
+ (void) pthread_mutex_lock(&self->cancelLock);
+ if (self->state < PThreadStateCanceling)
+ {
+ self->state = PThreadStateCanceling;
+ self->cancelState = PTHREAD_CANCEL_DISABLE;
+ (void) pthread_mutex_unlock(&self->cancelLock);
+ ptw32_throw(PTW32_EPS_CANCEL);
+
+ /* Never reached */
+ }
+ (void) pthread_mutex_unlock(&self->cancelLock);
+ }
+
+ /* Should never get to here. */
+ result = EINVAL;
+ break;
+
+ default:
+ if (status == WAIT_TIMEOUT)
+ {
+ result = ETIMEDOUT;
+ }
+ else
+ {
+ result = EINVAL;
+ }
+ break;
}
- (void) pthread_mutex_unlock(&self->cancelLock);
- }
-
- /* Should never get to here. */
- result = EINVAL;
- break;
-
- default:
- result = EINVAL;
- break;
- }
- }
return (result);