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 @@ #import -@class CSBestEffortUpdater; - -@protocol CSBestEffortUpdaterDelegate - -- (void)bestEffortUpdater:(CSBestEffortUpdater *)bestEffortUpdater runForInterval:(NSTimeInterval)interval didSkipPreviousUpdate:(BOOL)didSkipPreviousUpdate; - -@end - +#import "CSMachine.h" @interface CSBestEffortUpdater : NSObject -@property (nonatomic, weak) id 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 delegate; - NSLock *delegateLock; + __weak CSMachine *machine; - void update(Concurrency::BestEffortUpdater *updater, Time::Seconds cycles, bool did_skip_previous_update) { - [delegateLock lock]; - __weak id 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)delegate { - [_delegateLock lock]; - _updaterDelegate.delegate = delegate; - [_delegateLock unlock]; -} - -- (id)delegate { - id 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;