diff options
author | rpj <rpj> | 2004-11-03 01:08:41 +0000 |
---|---|---|
committer | rpj <rpj> | 2004-11-03 01:08:41 +0000 |
commit | ec8290acdaea21b16d98f1ef5d4ae8a28ab2109a (patch) | |
tree | 0bd3750ec1cc12594b6cfe69473e393da6ec101b /pthread_testcancel.c | |
parent | cccaf0c2c82e78a72d69a4a50c872f308bed2f65 (diff) |
Mutex, semaphore, thread ID, test suite changes - see ChangeLogs
Diffstat (limited to 'pthread_testcancel.c')
-rw-r--r-- | pthread_testcancel.c | 35 |
1 files changed, 24 insertions, 11 deletions
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 */ |