From d7c1caecf19cb678a2978f47c45fe4c535bbc67f Mon Sep 17 00:00:00 2001 From: "Jake.Stine" Date: Mon, 21 Dec 2009 00:30:08 +0000 Subject: [PATCH] w32pthreads: only half-fixed the cancellation counter before. This should full-like fix it. git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2373 96395faa-99c1-11dd-bbfe-3dabce05a288 --- 3rdparty/w32pthreads/ptw32_threadStart.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/3rdparty/w32pthreads/ptw32_threadStart.c b/3rdparty/w32pthreads/ptw32_threadStart.c index 74216210eb..ba78e3bd61 100644 --- a/3rdparty/w32pthreads/ptw32_threadStart.c +++ b/3rdparty/w32pthreads/ptw32_threadStart.c @@ -46,27 +46,31 @@ static void _cleanup_testcancel_optimization( void* specific ) { ptw32_thread_t * sp = (ptw32_thread_t*)specific; //(ptw32_thread_t *)pthread_getspecific (ptw32_selfThreadKey); - if( (sp != NULL) ) + if( sp == NULL ) return; + + pthread_mutex_lock (&sp->cancelLock); + if( sp->cancelType == PTHREAD_CANCEL_DEFERRED ) { - pthread_mutex_lock (&sp->cancelLock); - if( (sp->cancelType == PTHREAD_CANCEL_DEFERRED) && (sp->state == PThreadStateCancelPending) ) + if( sp->state == PThreadStateCancelPending || sp->state == PThreadStateCanceling ) { int result = _InterlockedDecrement( &ptw32_testcancel_enable ); assert( result >= 0 ); sp->state = PThreadStateCanceling; } - else + else if( sp->state == PThreadStateRunning ) { // We need to prevent other threads, which may try to cancel this thread // in parallel to it's cancellation here, from incrementing the cancel_enable flag. // (and without clobbering the StateException, if that's already been set) - if( sp->state < PThreadStateCanceling ) - sp->state = PThreadStateCanceling; + sp->state = PThreadStateLast; + } + else + { + assert(0); } - - pthread_mutex_unlock (&sp->cancelLock); } + pthread_mutex_unlock (&sp->cancelLock); } #ifdef __CLEANUP_SEH