From 07ce0f0133a257f845423d11e37cb522c6fb1dcf Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 7 Jul 2022 16:56:10 -0400 Subject: [PATCH] Attempt safe shutdown. --- Concurrency/AsyncUpdater.hpp | 12 +++++++++--- OSBindings/Mac/Clock Signal/Machine/CSMachine.mm | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Concurrency/AsyncUpdater.hpp b/Concurrency/AsyncUpdater.hpp index 74e1fd334..12b937895 100644 --- a/Concurrency/AsyncUpdater.hpp +++ b/Concurrency/AsyncUpdater.hpp @@ -62,10 +62,16 @@ template class AsyncUpdater { condition_.notify_all(); } + void stop() { + if(performer_thread_.joinable()) { + should_quit = true; + update([] {}); + performer_thread_.join(); + } + } + ~AsyncUpdater() { - should_quit = true; - update([] {}); - performer_thread_.join(); + stop(); } // The object that will actually receive time advances. diff --git a/OSBindings/Mac/Clock Signal/Machine/CSMachine.mm b/OSBindings/Mac/Clock Signal/Machine/CSMachine.mm index ef588b7c2..bb66f3461 100644 --- a/OSBindings/Mac/Clock Signal/Machine/CSMachine.mm +++ b/OSBindings/Mac/Clock Signal/Machine/CSMachine.mm @@ -677,7 +677,6 @@ struct ActivityObserver: public Activity::Observer { #pragma mark - Timer - (void)audioQueueIsRunningDry:(nonnull CSAudioQueue *)audioQueue { - // TODO: Make audio flushes overt, and do one here. updater.update([self] { updater.performer.machine->flush_output(); }); @@ -692,6 +691,8 @@ struct ActivityObserver: public Activity::Observer { }); }); + // TODO: restory sync locking; see below. + // First order of business: grab a timestamp. /* const auto timeNow = Time::nanos_now(); @@ -724,6 +725,10 @@ struct ActivityObserver: public Activity::Observer { #define TICKS 120 - (void)start { +// _timer = [[CSHighPrecisionTimer alloc] initWithTask:^{ +// updater.update([] {}); +// } interval:uint64_t(1000000000) / uint64_t(TICKS)]; + // updater.performer.machine = _machine->timed_machine(); /* __block auto lastTime = Time::nanos_now(); @@ -805,8 +810,9 @@ struct ActivityObserver: public Activity::Observer { #undef TICKS - (void)stop { - [_timer invalidate]; - _timer = nil; + updater.stop(); +// [_timer invalidate]; +// _timer = nil; } + (BOOL)attemptInstallROM:(NSURL *)url {