From 878649a0a88dc64d608c999285c21507f1e2bd38 Mon Sep 17 00:00:00 2001 From: rogerman Date: Thu, 27 Nov 2014 05:36:45 +0000 Subject: [PATCH] Cocoa Port: - Remove the extra mutex from NDS_exec() in the main emulation loop. Have all consumers use the rwlock instead. --- desmume/src/cocoa/cocoa_GPU.h | 4 +- desmume/src/cocoa/cocoa_GPU.mm | 186 +++++++++--------- desmume/src/cocoa/cocoa_cheat.h | 14 +- desmume/src/cocoa/cocoa_cheat.mm | 142 ++++++------- desmume/src/cocoa/cocoa_core.h | 8 +- desmume/src/cocoa/cocoa_core.mm | 55 ++---- desmume/src/cocoa/cocoa_output.h | 6 +- desmume/src/cocoa/cocoa_output.mm | 35 ++-- desmume/src/cocoa/openemu/NDSGameCore.h | 4 +- desmume/src/cocoa/openemu/NDSGameCore.mm | 16 +- desmume/src/cocoa/openemu/OESoundInterface.mm | 10 +- desmume/src/cocoa/sndOSX.cpp | 10 +- desmume/src/cocoa/sndOSX.h | 4 +- .../userinterface/EmuControllerDelegate.mm | 2 +- 14 files changed, 239 insertions(+), 257 deletions(-) diff --git a/desmume/src/cocoa/cocoa_GPU.h b/desmume/src/cocoa/cocoa_GPU.h index b9892b088..d0d6f17c7 100644 --- a/desmume/src/cocoa/cocoa_GPU.h +++ b/desmume/src/cocoa/cocoa_GPU.h @@ -26,11 +26,11 @@ BOOL isCPUCoreCountAuto; OSSpinLock spinlockGpuState; - pthread_mutex_t *mutexProducer; + pthread_rwlock_t *rwlockProducer; } @property (assign) UInt32 gpuStateFlags; -@property (assign) pthread_mutex_t *mutexProducer; +@property (assign) pthread_rwlock_t *rwlockProducer; @property (assign) BOOL layerMainGPU; @property (assign) BOOL layerMainBG0; diff --git a/desmume/src/cocoa/cocoa_GPU.mm b/desmume/src/cocoa/cocoa_GPU.mm index 489dafffa..db5b79e0e 100644 --- a/desmume/src/cocoa/cocoa_GPU.mm +++ b/desmume/src/cocoa/cocoa_GPU.mm @@ -43,7 +43,7 @@ GPU3DInterface *core3DList[] = { @implementation CocoaDSGPU @dynamic gpuStateFlags; -@synthesize mutexProducer; +@synthesize rwlockProducer; @dynamic layerMainGPU; @dynamic layerMainBG0; @@ -79,7 +79,7 @@ GPU3DInterface *core3DList[] = { } spinlockGpuState = OS_SPINLOCK_INIT; - mutexProducer = NULL; + rwlockProducer = NULL; gpuStateFlags = GPUSTATE_MAIN_GPU_MASK | GPUSTATE_MAIN_BG0_MASK | @@ -143,96 +143,96 @@ GPU3DInterface *core3DList[] = { - (void) setRender3DRenderingEngine:(NSInteger)methodID { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_wrlock(self.rwlockProducer); NDS_3D_ChangeCore(methodID); - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); } - (NSInteger) render3DRenderingEngine { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_rdlock(self.rwlockProducer); const NSInteger methodID = (NSInteger)cur3DCore; - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); return methodID; } - (void) setRender3DHighPrecisionColorInterpolation:(BOOL)state { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_wrlock(self.rwlockProducer); CommonSettings.GFX3D_HighResolutionInterpolateColor = state ? true : false; - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); } - (BOOL) render3DHighPrecisionColorInterpolation { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_rdlock(self.rwlockProducer); const BOOL state = CommonSettings.GFX3D_HighResolutionInterpolateColor ? YES : NO; - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); return state; } - (void) setRender3DEdgeMarking:(BOOL)state { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_wrlock(self.rwlockProducer); CommonSettings.GFX3D_EdgeMark = state ? true : false; - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); } - (BOOL) render3DEdgeMarking { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_rdlock(self.rwlockProducer); const BOOL state = CommonSettings.GFX3D_EdgeMark ? YES : NO; - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); return state; } - (void) setRender3DFog:(BOOL)state { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_wrlock(self.rwlockProducer); CommonSettings.GFX3D_Fog = state ? true : false; - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); } - (BOOL) render3DFog { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_rdlock(self.rwlockProducer); const BOOL state = CommonSettings.GFX3D_Fog ? YES : NO; - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); return state; } - (void) setRender3DTextures:(BOOL)state { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_wrlock(self.rwlockProducer); CommonSettings.GFX3D_Texture = state ? true : false; - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); } - (BOOL) render3DTextures { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_rdlock(self.rwlockProducer); const BOOL state = CommonSettings.GFX3D_Texture ? YES : NO; - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); return state; } - (void) setRender3DDepthComparisonThreshold:(NSUInteger)threshold { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_wrlock(self.rwlockProducer); CommonSettings.GFX3D_Zelda_Shadow_Depth_Hack = threshold; - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); } - (NSUInteger) render3DDepthComparisonThreshold { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_rdlock(self.rwlockProducer); const NSUInteger threshold = (NSUInteger)CommonSettings.GFX3D_Zelda_Shadow_Depth_Hack; - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); return threshold; } @@ -269,7 +269,7 @@ GPU3DInterface *core3DList[] = { const NSInteger renderingEngineID = [self render3DRenderingEngine]; - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_wrlock(self.rwlockProducer); CommonSettings.num_cores = numberCores; @@ -278,71 +278,71 @@ GPU3DInterface *core3DList[] = { NDS_3D_ChangeCore(renderingEngineID); } - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); } - (NSUInteger) render3DThreads { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_rdlock(self.rwlockProducer); const NSUInteger numberThreads = isCPUCoreCountAuto ? 0 : (NSUInteger)CommonSettings.num_cores; - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); return numberThreads; } - (void) setRender3DLineHack:(BOOL)state { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_wrlock(self.rwlockProducer); CommonSettings.GFX3D_LineHack = state ? true : false; - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); } - (BOOL) render3DLineHack { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_rdlock(self.rwlockProducer); const BOOL state = CommonSettings.GFX3D_LineHack ? YES : NO; - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); return state; } - (void) setRender3DMultisample:(BOOL)state { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_wrlock(self.rwlockProducer); CommonSettings.GFX3D_Renderer_Multisample = state ? true : false; - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); } - (BOOL) render3DMultisample { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_rdlock(self.rwlockProducer); const BOOL state = CommonSettings.GFX3D_Renderer_Multisample ? YES : NO; - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); return state; } - (void) setRender3DFragmentSamplingHack:(BOOL)state { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_wrlock(self.rwlockProducer); CommonSettings.GFX3D_TXTHack = state ? true : false; - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); } - (BOOL) render3DFragmentSamplingHack { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_rdlock(self.rwlockProducer); const BOOL state = CommonSettings.GFX3D_TXTHack ? YES : NO; - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); return state; } - (void) setLayerMainGPU:(BOOL)gpuState { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_wrlock(self.rwlockProducer); SetGPUDisplayState(DS_GPU_TYPE_MAIN, (gpuState) ? true : false); - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); OSSpinLockLock(&spinlockGpuState); gpuStateFlags = (gpuState) ? (gpuStateFlags | GPUSTATE_MAIN_GPU_MASK) : (gpuStateFlags & ~GPUSTATE_MAIN_GPU_MASK); @@ -351,18 +351,18 @@ GPU3DInterface *core3DList[] = { - (BOOL) layerMainGPU { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_rdlock(self.rwlockProducer); const BOOL gpuState = GetGPUDisplayState(DS_GPU_TYPE_MAIN) ? YES : NO; - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); return gpuState; } - (void) setLayerMainBG0:(BOOL)layerState { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_wrlock(self.rwlockProducer); SetGPULayerState(DS_GPU_TYPE_MAIN, 0, (layerState) ? true : false); - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); OSSpinLockLock(&spinlockGpuState); gpuStateFlags = (layerState) ? (gpuStateFlags | GPUSTATE_MAIN_BG0_MASK) : (gpuStateFlags & ~GPUSTATE_MAIN_BG0_MASK); @@ -371,18 +371,18 @@ GPU3DInterface *core3DList[] = { - (BOOL) layerMainBG0 { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_rdlock(self.rwlockProducer); const BOOL layerState = GetGPULayerState(DS_GPU_TYPE_MAIN, 0) ? YES : NO; - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); return layerState; } - (void) setLayerMainBG1:(BOOL)layerState { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_wrlock(self.rwlockProducer); SetGPULayerState(DS_GPU_TYPE_MAIN, 1, (layerState) ? true : false); - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); OSSpinLockLock(&spinlockGpuState); gpuStateFlags = (layerState) ? (gpuStateFlags | GPUSTATE_MAIN_BG1_MASK) : (gpuStateFlags & ~GPUSTATE_MAIN_BG1_MASK); @@ -391,18 +391,18 @@ GPU3DInterface *core3DList[] = { - (BOOL) layerMainBG1 { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_rdlock(self.rwlockProducer); const BOOL layerState = GetGPULayerState(DS_GPU_TYPE_MAIN, 1) ? YES : NO; - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); return layerState; } - (void) setLayerMainBG2:(BOOL)layerState { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_wrlock(self.rwlockProducer); SetGPULayerState(DS_GPU_TYPE_MAIN, 2, (layerState) ? true : false); - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); OSSpinLockLock(&spinlockGpuState); gpuStateFlags = (layerState) ? (gpuStateFlags | GPUSTATE_MAIN_BG2_MASK) : (gpuStateFlags & ~GPUSTATE_MAIN_BG2_MASK); @@ -411,18 +411,18 @@ GPU3DInterface *core3DList[] = { - (BOOL) layerMainBG2 { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_rdlock(self.rwlockProducer); const BOOL layerState = GetGPULayerState(DS_GPU_TYPE_MAIN, 2) ? YES : NO; - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); return layerState; } - (void) setLayerMainBG3:(BOOL)layerState { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_wrlock(self.rwlockProducer); SetGPULayerState(DS_GPU_TYPE_MAIN, 3, (layerState) ? true : false); - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); OSSpinLockLock(&spinlockGpuState); gpuStateFlags = (layerState) ? (gpuStateFlags | GPUSTATE_MAIN_BG3_MASK) : (gpuStateFlags & ~GPUSTATE_MAIN_BG3_MASK); @@ -431,18 +431,18 @@ GPU3DInterface *core3DList[] = { - (BOOL) layerMainBG3 { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_rdlock(self.rwlockProducer); const BOOL layerState = GetGPULayerState(DS_GPU_TYPE_MAIN, 3) ? YES : NO; - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); return layerState; } - (void) setLayerMainOBJ:(BOOL)layerState { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_wrlock(self.rwlockProducer); SetGPULayerState(DS_GPU_TYPE_MAIN, 4, (layerState) ? true : false); - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); OSSpinLockLock(&spinlockGpuState); gpuStateFlags = (layerState) ? (gpuStateFlags | GPUSTATE_MAIN_OBJ_MASK) : (gpuStateFlags & ~GPUSTATE_MAIN_OBJ_MASK); @@ -451,18 +451,18 @@ GPU3DInterface *core3DList[] = { - (BOOL) layerMainOBJ { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_rdlock(self.rwlockProducer); const BOOL layerState = GetGPULayerState(DS_GPU_TYPE_MAIN, 4) ? YES : NO; - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); return layerState; } - (void) setLayerSubGPU:(BOOL)gpuState { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_wrlock(self.rwlockProducer); SetGPUDisplayState(DS_GPU_TYPE_SUB, (gpuState) ? true : false); - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); OSSpinLockLock(&spinlockGpuState); gpuStateFlags = (gpuState) ? (gpuStateFlags | GPUSTATE_SUB_GPU_MASK) : (gpuStateFlags & ~GPUSTATE_SUB_GPU_MASK); @@ -471,18 +471,18 @@ GPU3DInterface *core3DList[] = { - (BOOL) layerSubGPU { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_rdlock(self.rwlockProducer); const BOOL gpuState = GetGPUDisplayState(DS_GPU_TYPE_SUB) ? YES : NO; - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); return gpuState; } - (void) setLayerSubBG0:(BOOL)layerState { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_wrlock(self.rwlockProducer); SetGPULayerState(DS_GPU_TYPE_SUB, 0, (layerState) ? true : false); - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); OSSpinLockLock(&spinlockGpuState); gpuStateFlags = (layerState) ? (gpuStateFlags | GPUSTATE_SUB_BG0_MASK) : (gpuStateFlags & ~GPUSTATE_SUB_BG0_MASK); @@ -491,18 +491,18 @@ GPU3DInterface *core3DList[] = { - (BOOL) layerSubBG0 { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_rdlock(self.rwlockProducer); const BOOL layerState = GetGPULayerState(DS_GPU_TYPE_SUB, 0) ? YES : NO; - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); return layerState; } - (void) setLayerSubBG1:(BOOL)layerState { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_wrlock(self.rwlockProducer); SetGPULayerState(DS_GPU_TYPE_SUB, 1, (layerState) ? true : false); - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); OSSpinLockLock(&spinlockGpuState); gpuStateFlags = (layerState) ? (gpuStateFlags | GPUSTATE_SUB_BG1_MASK) : (gpuStateFlags & ~GPUSTATE_SUB_BG1_MASK); @@ -511,18 +511,18 @@ GPU3DInterface *core3DList[] = { - (BOOL) layerSubBG1 { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_rdlock(self.rwlockProducer); const BOOL layerState = GetGPULayerState(DS_GPU_TYPE_SUB, 1) ? YES : NO; - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); return layerState; } - (void) setLayerSubBG2:(BOOL)layerState { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_wrlock(self.rwlockProducer); SetGPULayerState(DS_GPU_TYPE_SUB, 2, (layerState) ? true : false); - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); OSSpinLockLock(&spinlockGpuState); gpuStateFlags = (layerState) ? (gpuStateFlags | GPUSTATE_SUB_BG2_MASK) : (gpuStateFlags & ~GPUSTATE_SUB_BG2_MASK); @@ -531,18 +531,18 @@ GPU3DInterface *core3DList[] = { - (BOOL) layerSubBG2 { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_rdlock(self.rwlockProducer); const BOOL layerState = GetGPULayerState(DS_GPU_TYPE_SUB, 2) ? YES : NO; - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); return layerState; } - (void) setLayerSubBG3:(BOOL)layerState { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_wrlock(self.rwlockProducer); SetGPULayerState(DS_GPU_TYPE_SUB, 3, (layerState) ? true : false); - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); OSSpinLockLock(&spinlockGpuState); gpuStateFlags = (layerState) ? (gpuStateFlags | GPUSTATE_SUB_BG3_MASK) : (gpuStateFlags & ~GPUSTATE_SUB_BG3_MASK); @@ -551,18 +551,18 @@ GPU3DInterface *core3DList[] = { - (BOOL) layerSubBG3 { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_rdlock(self.rwlockProducer); const BOOL layerState = GetGPULayerState(DS_GPU_TYPE_SUB, 3) ? YES : NO; - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); return layerState; } - (void) setLayerSubOBJ:(BOOL)layerState { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_wrlock(self.rwlockProducer); SetGPULayerState(DS_GPU_TYPE_SUB, 4, (layerState) ? true : false); - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); OSSpinLockLock(&spinlockGpuState); gpuStateFlags = (layerState) ? (gpuStateFlags | GPUSTATE_SUB_OBJ_MASK) : (gpuStateFlags & ~GPUSTATE_SUB_OBJ_MASK); @@ -571,9 +571,9 @@ GPU3DInterface *core3DList[] = { - (BOOL) layerSubOBJ { - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_rdlock(self.rwlockProducer); const BOOL layerState = GetGPULayerState(DS_GPU_TYPE_SUB, 4) ? YES : NO; - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); return layerState; } @@ -674,18 +674,18 @@ GPU3DInterface *core3DList[] = { { NSString *theString = @"Uninitialized"; - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_rdlock(self.rwlockProducer); if(gpu3D == NULL) { - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); return theString; } const char *theName = gpu3D->name; theString = [NSString stringWithCString:theName encoding:NSUTF8StringEncoding]; - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); return theString; } diff --git a/desmume/src/cocoa/cocoa_cheat.h b/desmume/src/cocoa/cocoa_cheat.h index 8f83cf256..e410e57e2 100644 --- a/desmume/src/cocoa/cocoa_cheat.h +++ b/desmume/src/cocoa/cocoa_cheat.h @@ -1,6 +1,6 @@ /* Copyright (C) 2011 Roger Manuel - Copyright (C) 2011-2013 DeSmuME team + Copyright (C) 2011-2014 DeSmuME team This file is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -94,8 +94,8 @@ CHEATS *listData; NSMutableArray *list; - pthread_mutex_t *mutexCoreExecute; - BOOL isUsingDummyMutex; + pthread_rwlock_t *rwlockCoreExecute; + BOOL isUsingDummyRWlock; NSUInteger untitledCount; NSString *dbTitle; @@ -104,7 +104,7 @@ @property (readonly) CHEATS *listData; @property (readonly) NSMutableArray *list; -@property (assign) pthread_mutex_t *mutexCoreExecute; +@property (assign) pthread_rwlock_t *rwlockCoreExecute; @property (assign) NSUInteger untitledCount; @property (copy) NSString *dbTitle; @property (copy) NSString *dbDate; @@ -135,15 +135,15 @@ CHEATSEARCH *listData; NSMutableArray *addressList; - pthread_mutex_t *mutexCoreExecute; - BOOL isUsingDummyMutex; + pthread_rwlock_t *rwlockCoreExecute; + BOOL isUsingDummyRWlock; NSUInteger searchCount; } @property (readonly) CHEATSEARCH *listData; @property (readonly) NSMutableArray *addressList; -@property (assign) pthread_mutex_t *mutexCoreExecute; +@property (assign) pthread_rwlock_t *rwlockCoreExecute; @property (readonly) NSUInteger searchCount; - (NSUInteger) runExactValueSearch:(NSInteger)value byteSize:(UInt8)byteSize signType:(NSInteger)signType; diff --git a/desmume/src/cocoa/cocoa_cheat.mm b/desmume/src/cocoa/cocoa_cheat.mm index f467caec1..5c7d97db8 100644 --- a/desmume/src/cocoa/cocoa_cheat.mm +++ b/desmume/src/cocoa/cocoa_cheat.mm @@ -1,6 +1,6 @@ /* Copyright (C) 2011 Roger Manuel - Copyright (C) 2012 DeSmuME team + Copyright (C) 2012-2014 DeSmuME team This file is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -660,7 +660,7 @@ static NSImage *iconCodeBreaker = nil; @synthesize listData; @synthesize list; -@dynamic mutexCoreExecute; +@dynamic rwlockCoreExecute; @synthesize untitledCount; @synthesize dbTitle; @synthesize dbDate; @@ -720,9 +720,9 @@ static NSImage *iconCodeBreaker = nil; } } - mutexCoreExecute = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t)); - pthread_mutex_init(mutexCoreExecute, NULL); - isUsingDummyMutex = YES; + rwlockCoreExecute = (pthread_rwlock_t *)malloc(sizeof(pthread_rwlock_t)); + pthread_rwlock_init(rwlockCoreExecute, NULL); + isUsingDummyRWlock = YES; untitledCount = 0; dbTitle = nil; @@ -738,45 +738,45 @@ static NSImage *iconCodeBreaker = nil; [list release]; delete (CHEATS *)self.listData; - if (isUsingDummyMutex) + if (isUsingDummyRWlock) { - pthread_mutex_destroy(mutexCoreExecute); - free(mutexCoreExecute); - mutexCoreExecute = NULL; + pthread_rwlock_destroy(rwlockCoreExecute); + free(rwlockCoreExecute); + rwlockCoreExecute = NULL; } [super dealloc]; } -- (void) setMutexCoreExecute:(pthread_mutex_t *)theMutex +- (void) setRwlockCoreExecute:(pthread_rwlock_t *)theRwlock { - if (theMutex == NULL && isUsingDummyMutex) + if (theRwlock == NULL && isUsingDummyRWlock) { return; } - else if (theMutex == NULL && !isUsingDummyMutex) + else if (theRwlock == NULL && !isUsingDummyRWlock) { - mutexCoreExecute = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t)); - pthread_mutex_init(mutexCoreExecute, NULL); - isUsingDummyMutex = YES; + rwlockCoreExecute = (pthread_rwlock_t *)malloc(sizeof(pthread_rwlock_t)); + pthread_rwlock_init(rwlockCoreExecute, NULL); + isUsingDummyRWlock = YES; return; } - else if (theMutex != NULL && isUsingDummyMutex) + else if (theRwlock != NULL && isUsingDummyRWlock) { - pthread_mutex_destroy(mutexCoreExecute); - free(mutexCoreExecute); - isUsingDummyMutex = NO; - mutexCoreExecute = theMutex; + pthread_rwlock_destroy(rwlockCoreExecute); + free(rwlockCoreExecute); + isUsingDummyRWlock = NO; + rwlockCoreExecute = theRwlock; } - else if (theMutex != NULL && !isUsingDummyMutex) + else if (theRwlock != NULL && !isUsingDummyRWlock) { - mutexCoreExecute = theMutex; + rwlockCoreExecute = theRwlock; } } -- (pthread_mutex_t *) mutexCoreExecute +- (pthread_rwlock_t *) rwlockCoreExecute { - return mutexCoreExecute; + return rwlockCoreExecute; } - (BOOL) add:(CocoaDSCheatItem *)cheatItem @@ -792,7 +792,7 @@ static NSImage *iconCodeBreaker = nil; // to check if the list got reallocated. CHEATS_LIST *cheatListData = self.listData->getListPtr(); - pthread_mutex_lock([self mutexCoreExecute]); + pthread_rwlock_wrlock(self.rwlockCoreExecute); switch (cheatItem.cheatType) { @@ -824,7 +824,7 @@ static NSImage *iconCodeBreaker = nil; break; } - pthread_mutex_unlock([self mutexCoreExecute]); + pthread_rwlock_unlock(self.rwlockCoreExecute); if (![self.list containsObject:cheatItem]) { @@ -864,9 +864,9 @@ static NSImage *iconCodeBreaker = nil; return; } - pthread_mutex_lock([self mutexCoreExecute]); + pthread_rwlock_wrlock(self.rwlockCoreExecute); self.listData->remove(selectionIndex); - pthread_mutex_unlock([self mutexCoreExecute]); + pthread_rwlock_unlock(self.rwlockCoreExecute); // Removing an item from the raw cheat list data shifts all higher elements // by one, so we need to do the same. @@ -895,7 +895,7 @@ static NSImage *iconCodeBreaker = nil; return result; } - pthread_mutex_lock([self mutexCoreExecute]); + pthread_rwlock_wrlock(self.rwlockCoreExecute); switch (cheatItem.cheatType) { @@ -927,7 +927,7 @@ static NSImage *iconCodeBreaker = nil; break; } - pthread_mutex_unlock([self mutexCoreExecute]); + pthread_rwlock_unlock(self.rwlockCoreExecute); [cheatItem update]; @@ -936,18 +936,18 @@ static NSImage *iconCodeBreaker = nil; - (BOOL) save { - pthread_mutex_lock([self mutexCoreExecute]); + pthread_rwlock_wrlock(self.rwlockCoreExecute); BOOL result = self.listData->save(); - pthread_mutex_unlock([self mutexCoreExecute]); + pthread_rwlock_unlock(self.rwlockCoreExecute); return result; } - (NSUInteger) activeCount { - pthread_mutex_lock([self mutexCoreExecute]); + pthread_rwlock_rdlock(self.rwlockCoreExecute); NSUInteger activeCheatsCount = self.listData->getActiveCount(); - pthread_mutex_unlock([self mutexCoreExecute]); + pthread_rwlock_unlock(self.rwlockCoreExecute); return activeCheatsCount; } @@ -999,9 +999,9 @@ static NSImage *iconCodeBreaker = nil; return; } - pthread_mutex_lock([self mutexCoreExecute]); + pthread_rwlock_wrlock(self.rwlockCoreExecute); [CocoaDSCheatManager applyInternalCheatWithItem:cheatItem]; - pthread_mutex_unlock([self mutexCoreExecute]); + pthread_rwlock_unlock(self.rwlockCoreExecute); } + (void) setMasterCheatList:(CocoaDSCheatManager *)cheatListManager @@ -1126,7 +1126,7 @@ static NSImage *iconCodeBreaker = nil; @synthesize listData; @synthesize addressList; -@dynamic mutexCoreExecute; +@dynamic rwlockCoreExecute; @synthesize searchCount; - (id)init @@ -1144,9 +1144,9 @@ static NSImage *iconCodeBreaker = nil; return nil; } - mutexCoreExecute = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t)); - pthread_mutex_init(mutexCoreExecute, NULL); - isUsingDummyMutex = YES; + rwlockCoreExecute = (pthread_rwlock_t *)malloc(sizeof(pthread_rwlock_t)); + pthread_rwlock_init(rwlockCoreExecute, NULL); + isUsingDummyRWlock = YES; listData = newListData; addressList = nil; @@ -1157,52 +1157,52 @@ static NSImage *iconCodeBreaker = nil; - (void)dealloc { - pthread_mutex_lock([self mutexCoreExecute]); + pthread_rwlock_wrlock(self.rwlockCoreExecute); self.listData->close(); - pthread_mutex_unlock([self mutexCoreExecute]); + pthread_rwlock_unlock(self.rwlockCoreExecute); [addressList release]; delete (CHEATSEARCH *)self.listData; - if (isUsingDummyMutex) + if (isUsingDummyRWlock) { - pthread_mutex_destroy(mutexCoreExecute); - free(mutexCoreExecute); - mutexCoreExecute = NULL; + pthread_rwlock_destroy(rwlockCoreExecute); + free(rwlockCoreExecute); + rwlockCoreExecute = NULL; } [super dealloc]; } -- (void) setMutexCoreExecute:(pthread_mutex_t *)theMutex +- (void) setRwlockCoreExecute:(pthread_rwlock_t *)theRwlock { - if (theMutex == NULL && isUsingDummyMutex) + if (theRwlock == NULL && isUsingDummyRWlock) { return; } - else if (theMutex == NULL && !isUsingDummyMutex) + else if (theRwlock == NULL && !isUsingDummyRWlock) { - mutexCoreExecute = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t)); - pthread_mutex_init(mutexCoreExecute, NULL); - isUsingDummyMutex = YES; + rwlockCoreExecute = (pthread_rwlock_t *)malloc(sizeof(pthread_mutex_t)); + pthread_rwlock_init(rwlockCoreExecute, NULL); + isUsingDummyRWlock = YES; return; } - else if (theMutex != NULL && isUsingDummyMutex) + else if (theRwlock != NULL && isUsingDummyRWlock) { - pthread_mutex_destroy(mutexCoreExecute); - free(mutexCoreExecute); - isUsingDummyMutex = NO; - mutexCoreExecute = theMutex; + pthread_rwlock_destroy(rwlockCoreExecute); + free(rwlockCoreExecute); + isUsingDummyRWlock = NO; + rwlockCoreExecute = theRwlock; } - else if (theMutex != NULL && !isUsingDummyMutex) + else if (theRwlock != NULL && !isUsingDummyRWlock) { - mutexCoreExecute = theMutex; + rwlockCoreExecute = theRwlock; } } -- (pthread_mutex_t *) mutexCoreExecute +- (pthread_rwlock_t *) rwlockCoreExecute { - return mutexCoreExecute; + return rwlockCoreExecute; } - (NSUInteger) runExactValueSearch:(NSInteger)value byteSize:(UInt8)byteSize signType:(NSInteger)signType @@ -1214,17 +1214,17 @@ static NSImage *iconCodeBreaker = nil; { byteSize--; - pthread_mutex_lock([self mutexCoreExecute]); + pthread_rwlock_rdlock(self.rwlockCoreExecute); listExists = (NSUInteger)self.listData->start((u8)CHEATSEARCH_SEARCHSTYLE_EXACT_VALUE, (u8)byteSize, (u8)signType); - pthread_mutex_unlock([self mutexCoreExecute]); + pthread_rwlock_unlock(self.rwlockCoreExecute); } if (listExists) { - pthread_mutex_lock([self mutexCoreExecute]); + pthread_rwlock_rdlock(self.rwlockCoreExecute); itemCount = (NSUInteger)self.listData->search((u32)value); NSMutableArray *newAddressList = [[CocoaDSCheatSearch addressListWithListObject:self.listData maxItems:100] retain]; - pthread_mutex_unlock([self mutexCoreExecute]); + pthread_rwlock_unlock(self.rwlockCoreExecute); [addressList release]; addressList = newAddressList; @@ -1251,18 +1251,18 @@ static NSImage *iconCodeBreaker = nil; { byteSize--; - pthread_mutex_lock([self mutexCoreExecute]); + pthread_rwlock_rdlock(self.rwlockCoreExecute); listExists = (NSUInteger)self.listData->start((u8)CHEATSEARCH_SEARCHSTYLE_COMPARATIVE, (u8)byteSize, (u8)signType); - pthread_mutex_unlock([self mutexCoreExecute]); + pthread_rwlock_unlock(self.rwlockCoreExecute); addressList = nil; } else { - pthread_mutex_lock([self mutexCoreExecute]); + pthread_rwlock_rdlock(self.rwlockCoreExecute); itemCount = (NSUInteger)self.listData->search((u8)typeID); NSMutableArray *newAddressList = [[CocoaDSCheatSearch addressListWithListObject:self.listData maxItems:100] retain]; - pthread_mutex_unlock([self mutexCoreExecute]); + pthread_rwlock_unlock(self.rwlockCoreExecute); [addressList release]; addressList = newAddressList; @@ -1286,9 +1286,9 @@ static NSImage *iconCodeBreaker = nil; - (void) reset { - pthread_mutex_lock([self mutexCoreExecute]); + pthread_rwlock_wrlock(self.rwlockCoreExecute); self.listData->close(); - pthread_mutex_unlock([self mutexCoreExecute]); + pthread_rwlock_unlock(self.rwlockCoreExecute); searchCount = 0; [addressList release]; diff --git a/desmume/src/cocoa/cocoa_core.h b/desmume/src/cocoa/cocoa_core.h index ef1fc1803..1b24b3b81 100644 --- a/desmume/src/cocoa/cocoa_core.h +++ b/desmume/src/cocoa/cocoa_core.h @@ -1,6 +1,6 @@ /* Copyright (C) 2011 Roger Manuel - Copyright (C) 2011-2013 DeSmuME team + Copyright (C) 2011-2014 DeSmuME team This file is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -39,11 +39,10 @@ typedef struct int framesToSkip; uint64_t timeBudgetMachAbsTime; bool exitThread; - pthread_mutex_t mutexCoreExecute; pthread_mutex_t mutexOutputList; pthread_mutex_t mutexThreadExecute; pthread_cond_t condThreadExecute; - pthread_rwlock_t rwCoreExecute; + pthread_rwlock_t rwlockCoreExecute; } CoreThreadParam; @interface CocoaDSCore : NSObject @@ -122,8 +121,7 @@ typedef struct @property (copy) NSURL *firmwareImageURL; @property (retain) NSURL *slot1R4URL; -@property (readonly) pthread_mutex_t *mutexCoreExecute; -@property (readonly) pthread_rwlock_t *rwCoreExecute; +@property (readonly) pthread_rwlock_t *rwlockCoreExecute; - (BOOL) ejectCardFlag; - (void) setEjectCardFlag; diff --git a/desmume/src/cocoa/cocoa_core.mm b/desmume/src/cocoa/cocoa_core.mm index b5e17ac84..72c2fdd45 100644 --- a/desmume/src/cocoa/cocoa_core.mm +++ b/desmume/src/cocoa/cocoa_core.mm @@ -75,8 +75,7 @@ volatile bool execute = true; @dynamic firmwareImageURL; @synthesize slot1R4URL; -@dynamic mutexCoreExecute; -@dynamic rwCoreExecute; +@dynamic rwlockCoreExecute; - (id)init { @@ -140,14 +139,13 @@ volatile bool execute = true; threadParam.timeBudgetMachAbsTime = *(uint64_t *)&timeBudgetAbsTime; threadParam.exitThread = false; - pthread_mutex_init(&threadParam.mutexCoreExecute, NULL); pthread_mutex_init(&threadParam.mutexOutputList, NULL); pthread_mutex_init(&threadParam.mutexThreadExecute, NULL); pthread_cond_init(&threadParam.condThreadExecute, NULL); - pthread_rwlock_init(&threadParam.rwCoreExecute, NULL); + pthread_rwlock_init(&threadParam.rwlockCoreExecute, NULL); pthread_create(&coreThread, NULL, &RunCoreThread, &threadParam); - [cdsGPU setMutexProducer:self.mutexCoreExecute]; + [cdsGPU setRwlockProducer:self.rwlockCoreExecute]; frameStatus = @"---"; executionSpeedStatus = @"1.00x"; @@ -177,8 +175,7 @@ volatile bool execute = true; pthread_mutex_destroy(&threadParam.mutexThreadExecute); pthread_cond_destroy(&threadParam.condThreadExecute); pthread_mutex_destroy(&threadParam.mutexOutputList); - pthread_mutex_destroy(&threadParam.mutexCoreExecute); - pthread_rwlock_destroy(&threadParam.rwCoreExecute); + pthread_rwlock_destroy(&threadParam.rwlockCoreExecute); NDS_DeInit(); @@ -316,7 +313,7 @@ volatile bool execute = true; emulationFlags = theFlags; OSSpinLockUnlock(&spinlockEmulationFlags); - pthread_mutex_lock(&threadParam.mutexCoreExecute); + pthread_rwlock_wrlock(&threadParam.rwlockCoreExecute); if (theFlags & EMULATION_ADVANCED_BUS_LEVEL_TIMING_MASK) { @@ -417,7 +414,7 @@ volatile bool execute = true; CommonSettings.DebugConsole = false; } - pthread_mutex_unlock(&threadParam.mutexCoreExecute); + pthread_rwlock_unlock(&threadParam.rwlockCoreExecute); } - (NSUInteger) emulationFlags @@ -451,16 +448,16 @@ volatile bool execute = true; - (void) setMaxJITBlockSize:(NSInteger)blockSize { - pthread_mutex_lock(&threadParam.mutexCoreExecute); + pthread_rwlock_wrlock(&threadParam.rwlockCoreExecute); CommonSettings.jit_max_block_size = (blockSize > 0) ? blockSize : 1; - pthread_mutex_unlock(&threadParam.mutexCoreExecute); + pthread_rwlock_unlock(&threadParam.rwlockCoreExecute); } - (NSInteger) maxJITBlockSize { - pthread_mutex_lock(&threadParam.mutexCoreExecute); + pthread_rwlock_rdlock(&threadParam.rwlockCoreExecute); const NSInteger blockSize = CommonSettings.jit_max_block_size; - pthread_mutex_unlock(&threadParam.mutexCoreExecute); + pthread_rwlock_unlock(&threadParam.rwlockCoreExecute); return blockSize; } @@ -594,14 +591,9 @@ volatile bool execute = true; return [NSURL fileURLWithPath:[NSString stringWithCString:CommonSettings.Firmware encoding:NSUTF8StringEncoding]]; } -- (pthread_mutex_t *) mutexCoreExecute +- (pthread_rwlock_t *) rwlockCoreExecute { - return &threadParam.mutexCoreExecute; -} - -- (pthread_rwlock_t *) rwCoreExecute -{ - return &threadParam.rwCoreExecute; + return &threadParam.rwlockCoreExecute; } - (void) setEjectCardFlag @@ -628,18 +620,18 @@ volatile bool execute = true; - (void) slot1Eject { - pthread_mutex_lock(&threadParam.mutexCoreExecute); + pthread_rwlock_wrlock(&threadParam.rwlockCoreExecute); NDS_TriggerCardEjectIRQ(); - pthread_mutex_unlock(&threadParam.mutexCoreExecute); + pthread_rwlock_unlock(&threadParam.rwlockCoreExecute); [self setSlot1StatusText:NSSTRING_STATUS_SLOT1_NO_DEVICE]; } - (void) changeRomSaveType:(NSInteger)saveTypeID { - pthread_mutex_lock(&threadParam.mutexCoreExecute); + pthread_rwlock_wrlock(&threadParam.rwlockCoreExecute); [CocoaDSRom changeRomSaveType:saveTypeID]; - pthread_mutex_unlock(&threadParam.mutexCoreExecute); + pthread_rwlock_unlock(&threadParam.rwlockCoreExecute); } - (void) changeExecutionSpeed @@ -755,9 +747,9 @@ volatile bool execute = true; - (NSUInteger) frameNumber { - pthread_mutex_lock(&threadParam.mutexCoreExecute); + pthread_rwlock_rdlock(&threadParam.rwlockCoreExecute); const NSUInteger currFrameNum = currFrameCounter; - pthread_mutex_unlock(&threadParam.mutexCoreExecute); + pthread_rwlock_unlock(&threadParam.rwlockCoreExecute); return currFrameNum; } @@ -786,8 +778,7 @@ volatile bool execute = true; - (void) addOutput:(CocoaDSOutput *)theOutput { pthread_mutex_lock(&threadParam.mutexOutputList); - [theOutput setMutexProducer:[self mutexCoreExecute]]; - [theOutput setRwProducer:[self rwCoreExecute]]; + [theOutput setRwlockProducer:[self rwlockCoreExecute]]; [[self cdsOutputList] addObject:theOutput]; pthread_mutex_unlock(&threadParam.mutexOutputList); } @@ -955,14 +946,10 @@ static void* RunCoreThread(void *arg) FCEUMOV_HandleRecording(); // Execute the frame and increment the frame counter. - pthread_mutex_lock(¶m->mutexCoreExecute); - - pthread_rwlock_wrlock(¶m->rwCoreExecute); + pthread_rwlock_wrlock(¶m->rwlockCoreExecute); NDS_exec(); - pthread_rwlock_unlock(¶m->rwCoreExecute); - frameNum = currFrameCounter; - pthread_mutex_unlock(¶m->mutexCoreExecute); + pthread_rwlock_unlock(¶m->rwlockCoreExecute); // Check if an internal execution error occurred that halted the emulation. if (!execute) diff --git a/desmume/src/cocoa/cocoa_output.h b/desmume/src/cocoa/cocoa_output.h index 5e793d009..86ee148bd 100644 --- a/desmume/src/cocoa/cocoa_output.h +++ b/desmume/src/cocoa/cocoa_output.h @@ -50,9 +50,8 @@ typedef struct NSData *frameAttributesData; NSMutableDictionary *property; - pthread_mutex_t *mutexProducer; pthread_mutex_t *mutexConsume; - pthread_rwlock_t *rwProducer; + pthread_rwlock_t *rwlockProducer; } @property (assign) BOOL isStateChanged; @@ -60,8 +59,7 @@ typedef struct @property (retain) NSData *frameData; @property (retain) NSData *frameAttributesData; @property (readonly) NSMutableDictionary *property; -@property (assign) pthread_mutex_t *mutexProducer; -@property (assign) pthread_rwlock_t *rwProducer; +@property (assign) pthread_rwlock_t *rwlockProducer; @property (readonly) pthread_mutex_t *mutexConsume; - (void) doCoreEmuFrame; diff --git a/desmume/src/cocoa/cocoa_output.mm b/desmume/src/cocoa/cocoa_output.mm index 9dfed76ff..719b56079 100644 --- a/desmume/src/cocoa/cocoa_output.mm +++ b/desmume/src/cocoa/cocoa_output.mm @@ -38,9 +38,8 @@ @synthesize frameData; @synthesize frameAttributesData; @synthesize property; -@synthesize mutexProducer; @synthesize mutexConsume; -@synthesize rwProducer; +@synthesize rwlockProducer; - (id)init { @@ -203,7 +202,7 @@ [property setValue:[NSNumber numberWithInteger:methodID] forKey:@"audioOutputEngine"]; OSSpinLockUnlock(&spinlockAudioOutputEngine); - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_wrlock(self.rwlockProducer); NSInteger result = -1; @@ -217,9 +216,9 @@ SPU_ChangeSoundCore(SNDCORE_DUMMY, 0); } - mutexAudioEmulateCore = self.mutexProducer; + rwlockAudioEmulateCore = self.rwlockProducer; - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); // Force the volume back to it's original setting. [self setVolume:[self volume]]; @@ -240,9 +239,9 @@ [property setValue:[NSNumber numberWithBool:state] forKey:@"spuAdvancedLogic"]; OSSpinLockUnlock(&spinlockSpuAdvancedLogic); - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_wrlock(self.rwlockProducer); CommonSettings.spu_advanced = state; - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); } - (BOOL) spuAdvancedLogic @@ -260,9 +259,9 @@ [property setValue:[NSNumber numberWithInteger:modeID] forKey:@"spuInterpolationMode"]; OSSpinLockUnlock(&spinlockSpuInterpolationMode); - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_wrlock(self.rwlockProducer); CommonSettings.spuInterpolationMode = (SPUInterpolationMode)modeID; - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); } - (NSInteger) spuInterpolationMode @@ -280,10 +279,10 @@ [property setValue:[NSNumber numberWithInteger:modeID] forKey:@"spuSyncMode"]; OSSpinLockUnlock(&spinlockSpuSyncMode); - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_wrlock(self.rwlockProducer); CommonSettings.SPU_sync_mode = (int)modeID; SPU_SetSynchMode(CommonSettings.SPU_sync_mode, CommonSettings.SPU_sync_method); - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); } - (NSInteger) spuSyncMode @@ -301,10 +300,10 @@ [property setValue:[NSNumber numberWithInteger:methodID] forKey:@"spuSyncMethod"]; OSSpinLockUnlock(&spinlockSpuSyncMethod); - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_wrlock(self.rwlockProducer); CommonSettings.SPU_sync_method = (int)methodID; SPU_SetSynchMode(CommonSettings.SPU_sync_mode, CommonSettings.SPU_sync_method); - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); } - (NSInteger) spuSyncMethod @@ -349,19 +348,19 @@ { NSString *theString = @"Uninitialized"; - pthread_mutex_lock(self.mutexProducer); + pthread_rwlock_rdlock(self.rwlockProducer); SoundInterface_struct *soundCore = SPU_SoundCore(); if(soundCore == NULL) { - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); return theString; } const char *theName = soundCore->Name; theString = [NSString stringWithCString:theName encoding:NSUTF8StringEncoding]; - pthread_mutex_unlock(self.mutexProducer); + pthread_rwlock_unlock(self.rwlockProducer); return theString; } @@ -929,7 +928,7 @@ // depending on the display mode, we copy only the pixels from the respective // screen. - pthread_rwlock_rdlock([self rwProducer]); + pthread_rwlock_rdlock(self.rwlockProducer); switch (frameDisplayMode) { @@ -949,7 +948,7 @@ break; } - pthread_rwlock_unlock([self rwProducer]); + pthread_rwlock_unlock(self.rwlockProducer); } [(id)delegate doProcessVideoFrame:[newVideoFrame bytes] displayMode:frameDisplayMode width:frameWidth height:frameHeight]; diff --git a/desmume/src/cocoa/openemu/NDSGameCore.h b/desmume/src/cocoa/openemu/NDSGameCore.h index b223017c4..d4687fad1 100644 --- a/desmume/src/cocoa/openemu/NDSGameCore.h +++ b/desmume/src/cocoa/openemu/NDSGameCore.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2013 DeSmuME team + Copyright (C) 2012-2014 DeSmuME team This file is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -40,7 +40,7 @@ NSInteger inputID[OENDSButtonCount]; // Key = OpenEmu's input ID, Value = DeSmuME's input ID OSSpinLock spinlockDisplayMode; - pthread_mutex_t mutexCoreExecute; + pthread_rwlock_t rwlockCoreExecute; } @property (retain) CocoaDSCheatManager *cdsCheats; diff --git a/desmume/src/cocoa/openemu/NDSGameCore.mm b/desmume/src/cocoa/openemu/NDSGameCore.mm index 74aff4caf..4ebfe08d7 100644 --- a/desmume/src/cocoa/openemu/NDSGameCore.mm +++ b/desmume/src/cocoa/openemu/NDSGameCore.mm @@ -50,7 +50,7 @@ volatile bool execute = true; // Set up threading locks spinlockDisplayMode = OS_SPINLOCK_INIT; - pthread_mutex_init(&mutexCoreExecute, NULL); + pthread_rwlock_init(&rwlockCoreExecute, NULL); // Set up input handling touchLocation.x = 0; @@ -78,7 +78,7 @@ volatile bool execute = true; // Set up the DS GPU cdsGPU = [[[[CocoaDSGPU alloc] init] retain] autorelease]; - [cdsGPU setMutexProducer:&mutexCoreExecute]; + [cdsGPU setRwlockProducer:&rwlockCoreExecute]; [cdsGPU setRender3DThreads:0]; // Pass 0 to automatically set the number of rendering threads [cdsGPU setRender3DRenderingEngine:CORE3DLIST_SWRASTERIZE]; @@ -90,7 +90,7 @@ volatile bool execute = true; // Set up the cheat system cdsCheats = [[[[CocoaDSCheatManager alloc] init] retain] autorelease]; - [cdsCheats setMutexCoreExecute:&mutexCoreExecute]; + [cdsCheats setRwlockCoreExecute:&rwlockCoreExecute]; // Set up the DS firmware using the internal firmware cdsFirmware = [[[[CocoaDSFirmware alloc] init] retain] autorelease]; @@ -130,7 +130,7 @@ volatile bool execute = true; [self setCdsGPU:nil]; [self setCdsFirmware:nil]; - pthread_mutex_destroy(&mutexCoreExecute); + pthread_rwlock_destroy(&rwlockCoreExecute); [super dealloc]; } @@ -184,9 +184,9 @@ volatile bool execute = true; - (void)resetEmulation { - pthread_mutex_lock(&mutexCoreExecute); + pthread_rwlock_wrlock(&rwlockCoreExecute); NDS_Reset(); - pthread_mutex_unlock(&mutexCoreExecute); + pthread_rwlock_unlock(&rwlockCoreExecute); execute = true; } @@ -207,9 +207,9 @@ volatile bool execute = true; NDS_beginProcessingInput(); NDS_endProcessingInput(); - pthread_mutex_lock(&mutexCoreExecute); + pthread_rwlock_wrlock(&rwlockCoreExecute); NDS_exec(); - pthread_mutex_unlock(&mutexCoreExecute); + pthread_rwlock_unlock(&rwlockCoreExecute); SPU_Emulate_user(); } diff --git a/desmume/src/cocoa/openemu/OESoundInterface.mm b/desmume/src/cocoa/openemu/OESoundInterface.mm index cc9a8f501..b44378b18 100644 --- a/desmume/src/cocoa/openemu/OESoundInterface.mm +++ b/desmume/src/cocoa/openemu/OESoundInterface.mm @@ -1,5 +1,5 @@ /* - Copyright (C) 2012 DeSmuME team + Copyright (C) 2012-2014 DeSmuME team This file is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -22,7 +22,7 @@ OERingBuffer *openEmuSoundInterfaceBuffer = nil; static pthread_mutex_t *mutexAudioSampleReadWrite = NULL; -pthread_mutex_t *mutexAudioEmulateCore = NULL; +pthread_rwlock_t *rwlockAudioEmulateCore = NULL; // Sound interface to the SPU SoundInterface_struct SNDOpenEmu = { @@ -124,11 +124,11 @@ size_t SNDOpenEmuPostProcessSamples(s16 *postProcessBuffer, size_t requestedSamp switch (synchMode) { case ESynchMode_DualSynchAsynch: - if (mutexAudioEmulateCore != NULL) + if (rwlockAudioEmulateCore != NULL) { - pthread_mutex_lock(mutexAudioEmulateCore); + pthread_rwlock_wrlock(rwlockAudioEmulateCore); processedSampleCount = SPU_DefaultPostProcessSamples(postProcessBuffer, requestedSampleCount, synchMode, theSynchronizer); - pthread_mutex_unlock(mutexAudioEmulateCore); + pthread_rwlock_unlock(rwlockAudioEmulateCore); } break; diff --git a/desmume/src/cocoa/sndOSX.cpp b/desmume/src/cocoa/sndOSX.cpp index bee83d4bd..a1f1d1df3 100644 --- a/desmume/src/cocoa/sndOSX.cpp +++ b/desmume/src/cocoa/sndOSX.cpp @@ -1,6 +1,6 @@ /* Copyright (C) 2007 Jeff Bland - Copyright (C) 2007-2013 DeSmuME team + Copyright (C) 2007-2014 DeSmuME team This file is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -25,7 +25,7 @@ // Global sound playback manager static CoreAudioOutput *coreAudioPlaybackManager = NULL; static pthread_mutex_t *mutexAudioSampleReadWrite = NULL; -pthread_mutex_t *mutexAudioEmulateCore = NULL; +pthread_rwlock_t *rwlockAudioEmulateCore = NULL; // Sound interface to the SPU SoundInterface_struct SNDOSX = { @@ -197,11 +197,11 @@ size_t SNDOSXPostProcessSamples(s16 *postProcessBuffer, size_t requestedSampleCo switch (synchMode) { case ESynchMode_DualSynchAsynch: - if (mutexAudioEmulateCore != NULL) + if (rwlockAudioEmulateCore != NULL) { - pthread_mutex_lock(mutexAudioEmulateCore); + pthread_rwlock_wrlock(rwlockAudioEmulateCore); processedSampleCount = SPU_DefaultPostProcessSamples(postProcessBuffer, requestedSampleCount, synchMode, theSynchronizer); - pthread_mutex_unlock(mutexAudioEmulateCore); + pthread_rwlock_unlock(rwlockAudioEmulateCore); } break; diff --git a/desmume/src/cocoa/sndOSX.h b/desmume/src/cocoa/sndOSX.h index ad25db024..28b77191b 100644 --- a/desmume/src/cocoa/sndOSX.h +++ b/desmume/src/cocoa/sndOSX.h @@ -1,6 +1,6 @@ /* Copyright (C) 2007 Jeff Bland - Copyright (C) 2007-2013 DeSmuME team + Copyright (C) 2007-2014 DeSmuME team This file is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -26,7 +26,7 @@ #define SNDCORE_OSX 58325 //hopefully this is unique number extern SoundInterface_struct SNDOSX; // Sound interface to the SPU -extern pthread_mutex_t *mutexAudioEmulateCore; // Mutex for the emulation core - used when mixing audio in Dual Synch/Asynch mode in post-process +extern pthread_rwlock_t *rwlockAudioEmulateCore; // RWlock for the emulation core - used when mixing audio in Dual Synch/Asynch mode in post-process // Core Audio functions for the sound interface int SNDOSXInit(int buffer_size); diff --git a/desmume/src/cocoa/userinterface/EmuControllerDelegate.mm b/desmume/src/cocoa/userinterface/EmuControllerDelegate.mm index 62954cccb..bc09d76ba 100644 --- a/desmume/src/cocoa/userinterface/EmuControllerDelegate.mm +++ b/desmume/src/cocoa/userinterface/EmuControllerDelegate.mm @@ -1726,7 +1726,7 @@ } [cheatWindowDelegate setCdsCheats:newCheatList]; - [[cheatWindowDelegate cdsCheatSearch] setMutexCoreExecute:[cdsCore mutexCoreExecute]]; + [[cheatWindowDelegate cdsCheatSearch] setRwlockCoreExecute:[cdsCore rwlockCoreExecute]]; [cheatWindowDelegate setCheatSearchViewByStyle:CHEATSEARCH_SEARCHSTYLE_EXACT_VALUE]; }