diff --git a/Concurrency/BestEffortUpdater.cpp b/Concurrency/BestEffortUpdater.cpp index 17c2b942c..16aa97199 100644 --- a/Concurrency/BestEffortUpdater.cpp +++ b/Concurrency/BestEffortUpdater.cpp @@ -80,7 +80,7 @@ void BestEffortUpdater::update_loop() { // Cap running at 1/5th of a second, to avoid doing a huge amount of work after any // brief system interruption. const double duration = std::min(double(integer_duration) / 1e9, 0.2); - delegate->update(this, duration, has_skipped_); + delegate->update(this, duration, has_skipped_, 0); has_skipped_ = false; } } diff --git a/Concurrency/BestEffortUpdater.hpp b/Concurrency/BestEffortUpdater.hpp index 38688d415..f46490b85 100644 --- a/Concurrency/BestEffortUpdater.hpp +++ b/Concurrency/BestEffortUpdater.hpp @@ -33,7 +33,7 @@ class BestEffortUpdater { /// A delegate receives timing cues. struct Delegate { - virtual void update(BestEffortUpdater *updater, Time::Seconds duration, bool did_skip_previous_update) = 0; + virtual void update(BestEffortUpdater *updater, Time::Seconds duration, bool did_skip_previous_update, int flags) = 0; }; /// Sets the current delegate. diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal.xcscheme b/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal.xcscheme index 47f9c7286..1465a4f62 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal.xcscheme +++ b/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal.xcscheme @@ -67,7 +67,7 @@ </Testables> </TestAction> <LaunchAction - buildConfiguration = "Debug" + buildConfiguration = "Release" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" enableASanStackUseAfterReturn = "YES" diff --git a/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift b/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift index 698c07755..79dd8e6f7 100644 --- a/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift +++ b/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift @@ -15,7 +15,6 @@ class MachineDocument: CSMachineDelegate, CSOpenGLViewDelegate, CSOpenGLViewResponderDelegate, - CSBestEffortUpdaterDelegate, CSAudioQueueDelegate, CSROMReciverViewDelegate { @@ -98,7 +97,6 @@ class MachineDocument: bestEffortLock.lock() if let bestEffortUpdater = bestEffortUpdater { - bestEffortUpdater.delegate = nil bestEffortUpdater.flush() self.bestEffortUpdater = nil } @@ -221,8 +219,8 @@ class MachineDocument: openGLView.window!.makeKeyAndOrderFront(self) openGLView.window!.makeFirstResponder(openGLView) - // Start accepting best effort updates. - self.bestEffortUpdater!.delegate = self + // Start forwarding best-effort updates. + self.bestEffortUpdater!.setMachine(machine) } } diff --git a/OSBindings/Mac/Clock Signal/Updater/CSBestEffortUpdater.h b/OSBindings/Mac/Clock Signal/Updater/CSBestEffortUpdater.h index b206e54b2..24e22c088 100644 --- a/OSBindings/Mac/Clock Signal/Updater/CSBestEffortUpdater.h +++ b/OSBindings/Mac/Clock Signal/Updater/CSBestEffortUpdater.h @@ -9,20 +9,12 @@ #import <Foundation/Foundation.h> #import <CoreVideo/CoreVideo.h> -@class CSBestEffortUpdater; - -@protocol CSBestEffortUpdaterDelegate <NSObject> - -- (void)bestEffortUpdater:(CSBestEffortUpdater *)bestEffortUpdater runForInterval:(NSTimeInterval)interval didSkipPreviousUpdate:(BOOL)didSkipPreviousUpdate; - -@end - +#import "CSMachine.h" @interface CSBestEffortUpdater : NSObject -@property (nonatomic, weak) id<CSBestEffortUpdaterDelegate> delegate; - - (void)update; - (void)flush; +- (void)setMachine:(CSMachine *)machine; @end diff --git a/OSBindings/Mac/Clock Signal/Updater/CSBestEffortUpdater.mm b/OSBindings/Mac/Clock Signal/Updater/CSBestEffortUpdater.mm index bc22986db..5b5fd357b 100644 --- a/OSBindings/Mac/Clock Signal/Updater/CSBestEffortUpdater.mm +++ b/OSBindings/Mac/Clock Signal/Updater/CSBestEffortUpdater.mm @@ -11,38 +11,26 @@ #include "BestEffortUpdater.hpp" struct UpdaterDelegate: public Concurrency::BestEffortUpdater::Delegate { - __weak id<CSBestEffortUpdaterDelegate> delegate; - NSLock *delegateLock; + __weak CSMachine *machine; - void update(Concurrency::BestEffortUpdater *updater, Time::Seconds cycles, bool did_skip_previous_update) { - [delegateLock lock]; - __weak id<CSBestEffortUpdaterDelegate> delegateCopy = delegate; - [delegateLock unlock]; - - [delegateCopy bestEffortUpdater:nil runForInterval:(NSTimeInterval)cycles didSkipPreviousUpdate:did_skip_previous_update]; + void update(Concurrency::BestEffortUpdater *updater, Time::Seconds seconds, bool did_skip_previous_update, int flags) { + [machine runForInterval:seconds]; } }; @implementation CSBestEffortUpdater { Concurrency::BestEffortUpdater _updater; UpdaterDelegate _updaterDelegate; - NSLock *_delegateLock; } - (instancetype)init { self = [super init]; if(self) { - _delegateLock = [[NSLock alloc] init]; - _updaterDelegate.delegateLock = _delegateLock; _updater.set_delegate(&_updaterDelegate); } return self; } -//- (void)dealloc { -// _updater.flush(); -//} - - (void)update { _updater.update(); } @@ -51,20 +39,9 @@ struct UpdaterDelegate: public Concurrency::BestEffortUpdater::Delegate { _updater.flush(); } -- (void)setDelegate:(id<CSBestEffortUpdaterDelegate>)delegate { - [_delegateLock lock]; - _updaterDelegate.delegate = delegate; - [_delegateLock unlock]; -} - -- (id<CSBestEffortUpdaterDelegate>)delegate { - id<CSBestEffortUpdaterDelegate> delegate; - - [_delegateLock lock]; - delegate = _updaterDelegate.delegate; - [_delegateLock unlock]; - - return delegate; +- (void)setMachine:(CSMachine *)machine { + _updater.flush(); + _updaterDelegate.machine = machine; } @end diff --git a/OSBindings/SDL/main.cpp b/OSBindings/SDL/main.cpp index 4a44d0789..74710fad8 100644 --- a/OSBindings/SDL/main.cpp +++ b/OSBindings/SDL/main.cpp @@ -34,8 +34,8 @@ namespace { struct BestEffortUpdaterDelegate: public Concurrency::BestEffortUpdater::Delegate { - void update(Concurrency::BestEffortUpdater *updater, Time::Seconds duration, bool did_skip_previous_update) override { - machine->crt_machine()->run_for(duration); + void update(Concurrency::BestEffortUpdater *updater, Time::Seconds duration, bool did_skip_previous_update, int flags) override { + machine->crt_machine()->run_until(duration); } Machine::DynamicMachine *machine;