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
This commit is contained in:
Jake.Stine 2009-12-21 00:30:08 +00:00
parent 6b930a9cff
commit d7c1caecf1
1 changed files with 12 additions and 8 deletions

View File

@ -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