From bbffbb5dc23965c9abdec105d34586ec268cad3a Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 16 Feb 2016 20:35:45 -0500 Subject: [PATCH] Resolved deadlock if an invalidate call was sent to the Electron while it was in the middle of an update. --- .../Clock Signal/Documents/ElectronDocument.swift | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/OSBindings/Mac/Clock Signal/Documents/ElectronDocument.swift b/OSBindings/Mac/Clock Signal/Documents/ElectronDocument.swift index 23c5f68e3..f68fb0019 100644 --- a/OSBindings/Mac/Clock Signal/Documents/ElectronDocument.swift +++ b/OSBindings/Mac/Clock Signal/Documents/ElectronDocument.swift @@ -55,21 +55,24 @@ class ElectronDocument: MachineDocument { electron.setROM(data, slot: 15) } + lazy var actionLock = NSLock() override func close() { - objc_sync_enter(self) + actionLock.lock() electron.sync() openGLView.invalidate() openGLView.openGLContext!.makeCurrentContext() electron = nil + actionLock.unlock() + super.close() - objc_sync_exit(self) } // MARK: CSOpenGLViewDelegate override func runForNumberOfCycles(numberOfCycles: Int32) { - objc_sync_enter(self) - electron?.runForNumberOfCycles(numberOfCycles) - objc_sync_exit(self) + if actionLock.tryLock() { + electron?.runForNumberOfCycles(numberOfCycles) + actionLock.unlock() + } } override func openGLView(view: CSCathodeRayView, drawViewOnlyIfDirty onlyIfDirty: Bool) {