From d83b1a260c9d8544be36115cf9ef297d3b6de1bc Mon Sep 17 00:00:00 2001 From: rogerman Date: Thu, 12 Feb 2015 09:02:04 +0000 Subject: [PATCH] Cocoa Port: - Fix another freeze on app exit when running on OS X v10.5 Leopard. --- desmume/src/cocoa/cocoa_core.h | 1 - desmume/src/cocoa/cocoa_core.mm | 17 +++-------------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/desmume/src/cocoa/cocoa_core.h b/desmume/src/cocoa/cocoa_core.h index 7163c76d8..360fbc75c 100644 --- a/desmume/src/cocoa/cocoa_core.h +++ b/desmume/src/cocoa/cocoa_core.h @@ -40,7 +40,6 @@ typedef struct NSUInteger frameJumpTarget; int framesToSkip; uint64_t timeBudgetMachAbsTime; - bool exitThread; pthread_mutex_t mutexOutputList; pthread_mutex_t mutexThreadExecute; pthread_cond_t condThreadExecute; diff --git a/desmume/src/cocoa/cocoa_core.mm b/desmume/src/cocoa/cocoa_core.mm index fd7771b8d..83f6d0856 100644 --- a/desmume/src/cocoa/cocoa_core.mm +++ b/desmume/src/cocoa/cocoa_core.mm @@ -189,7 +189,6 @@ volatile bool execute = true; AbsoluteTime timeBudgetAbsTime = NanosecondsToAbsolute(*(Nanoseconds *)&timeBudgetNanoseconds); threadParam.timeBudgetMachAbsTime = *(uint64_t *)&timeBudgetAbsTime; - threadParam.exitThread = false; pthread_mutex_init(&threadParam.mutexOutputList, NULL); pthread_mutex_init(&threadParam.mutexThreadExecute, NULL); pthread_cond_init(&threadParam.condThreadExecute, NULL); @@ -221,11 +220,7 @@ volatile bool execute = true; [self setCdsFirmware:nil]; [self setCdsGPU:nil]; - pthread_mutex_lock(&threadParam.mutexThreadExecute); - threadParam.exitThread = true; - pthread_cond_signal(&threadParam.condThreadExecute); - pthread_mutex_unlock(&threadParam.mutexThreadExecute); - + pthread_cancel(coreThread); pthread_join(coreThread, NULL); coreThread = NULL; @@ -1070,19 +1065,13 @@ static void* RunCoreThread(void *arg) pthread_mutex_lock(¶m->mutexThreadExecute); timeBudget = param->timeBudgetMachAbsTime; - while (!(param->state != CORESTATE_PAUSE && execute && !param->exitThread)) + while (!(param->state != CORESTATE_PAUSE && execute)) { pthread_cond_wait(¶m->condThreadExecute, ¶m->mutexThreadExecute); startTime = mach_absolute_time(); timeBudget = param->timeBudgetMachAbsTime; } - if (param->exitThread) - { - pthread_mutex_unlock(¶m->mutexThreadExecute); - break; - } - if (param->state != CORESTATE_FRAMEJUMP) { [(CocoaDSController *)param->cdsController flush]; @@ -1222,7 +1211,7 @@ static void* RunCoreThread(void *arg) mach_wait_until(startTime + timeBudget); } - } while (!param->exitThread); + } while(true); return NULL; }