From e53e289e773c42a21097eaf148329dea5901de5e Mon Sep 17 00:00:00 2001 From: rogerman Date: Tue, 7 Jul 2015 21:24:19 +0000 Subject: [PATCH] Cocoa Port: - Add some additional locks when reading the GPU framebuffer. --- desmume/src/cocoa/cocoa_output.mm | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/desmume/src/cocoa/cocoa_output.mm b/desmume/src/cocoa/cocoa_output.mm index 9ef76612e..0129dcd0e 100644 --- a/desmume/src/cocoa/cocoa_output.mm +++ b/desmume/src/cocoa/cocoa_output.mm @@ -543,9 +543,9 @@ - (NSSize) displaySize { - OSSpinLockLock(&spinlockDisplayType); + pthread_rwlock_rdlock(self.rwlockProducer); NSSize size = NSMakeSize((CGFloat)GPU_GetFramebufferWidth(), (displayMode == DS_DISPLAY_TYPE_DUAL) ? (CGFloat)(GPU_GetFramebufferHeight() * 2): (CGFloat)GPU_GetFramebufferHeight()); - OSSpinLockUnlock(&spinlockDisplayType); + pthread_rwlock_unlock(self.rwlockProducer); return size; } @@ -616,6 +616,8 @@ - (void) handleEmuFrameProcessed { + pthread_rwlock_rdlock(self.rwlockProducer); + const uint16_t newGpuWidth = GPU_GetFramebufferWidth(); const uint16_t newGpuHeight = GPU_GetFramebufferHeight(); @@ -624,6 +626,8 @@ _gpuFrame.width = newGpuWidth; _gpuFrame.height = (_gpuFrame.displayModeID == DS_DISPLAY_TYPE_DUAL) ? newGpuHeight * 2 : newGpuHeight; + pthread_rwlock_unlock(self.rwlockProducer); + if (newGpuWidth != _gpuCurrentWidth || newGpuHeight != _gpuCurrentHeight) { if (delegate != nil && [delegate respondsToSelector:@selector(doDisplaySizeChanged:)])