From ec8290acdaea21b16d98f1ef5d4ae8a28ab2109a Mon Sep 17 00:00:00 2001 From: rpj Date: Wed, 3 Nov 2004 01:08:41 +0000 Subject: Mutex, semaphore, thread ID, test suite changes - see ChangeLogs --- pthread_testcancel.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'pthread_testcancel.c') diff --git a/pthread_testcancel.c b/pthread_testcancel.c index 04c214a..2a1c080 100644 --- a/pthread_testcancel.c +++ b/pthread_testcancel.c @@ -69,21 +69,34 @@ pthread_testcancel (void) */ { pthread_t self = pthread_self (); + ptw32_thread_t * sp = (ptw32_thread_t *) self.p; - (void) pthread_mutex_lock (&self->cancelLock); + if (sp == NULL) + { + return; + } + + /* + * Pthread_cancel() will have set sp->state to PThreadStateCancelPending + * and set an event, so no need to enter kernel space if + * sp->state != PThreadStateCancelPending - that only slows us down. + */ + if (sp->state != PThreadStateCancelPending) + { + return; + } + + (void) pthread_mutex_lock (&sp->cancelLock); - if (self != NULL - && self->cancelState != PTHREAD_CANCEL_DISABLE - && WaitForSingleObject (self->cancelEvent, 0) == WAIT_OBJECT_0) + if (sp->cancelState != PTHREAD_CANCEL_DISABLE) { - /* - * Canceling! - */ - self->state = PThreadStateCanceling; - self->cancelState = PTHREAD_CANCEL_DISABLE; - (void) pthread_mutex_unlock (&self->cancelLock); + ResetEvent(sp->cancelEvent); + sp->state = PThreadStateCanceling; + (void) pthread_mutex_unlock (&sp->cancelLock); + sp->cancelState = PTHREAD_CANCEL_DISABLE; + (void) pthread_mutex_unlock (&sp->cancelLock); ptw32_throw (PTW32_EPS_CANCEL); } - (void) pthread_mutex_unlock (&self->cancelLock); + (void) pthread_mutex_unlock (&sp->cancelLock); } /* pthread_testcancel */ -- cgit v1.2.3