From 83f73c3f02216266d6e33c426c6d17cfe464be50 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Wed, 28 Feb 2018 22:15:22 -0500 Subject: [PATCH] Installs additional safeguards against unsafe deconstruction. --- Concurrency/AsyncTaskQueue.cpp | 4 ++++ Concurrency/AsyncTaskQueue.hpp | 4 +++- Concurrency/BestEffortUpdater.cpp | 5 +++++ Concurrency/BestEffortUpdater.hpp | 1 + OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift | 1 + 5 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Concurrency/AsyncTaskQueue.cpp b/Concurrency/AsyncTaskQueue.cpp index 6b8fd90f8..8775c4309 100644 --- a/Concurrency/AsyncTaskQueue.cpp +++ b/Concurrency/AsyncTaskQueue.cpp @@ -80,6 +80,10 @@ void AsyncTaskQueue::flush() { #endif } +DeferringAsyncTaskQueue::~DeferringAsyncTaskQueue() { + perform(); +} + void DeferringAsyncTaskQueue::defer(std::function function) { if(!deferred_tasks_) { deferred_tasks_.reset(new std::list>); diff --git a/Concurrency/AsyncTaskQueue.hpp b/Concurrency/AsyncTaskQueue.hpp index be8517454..577f97b1a 100644 --- a/Concurrency/AsyncTaskQueue.hpp +++ b/Concurrency/AsyncTaskQueue.hpp @@ -30,7 +30,7 @@ namespace Concurrency { class AsyncTaskQueue { public: AsyncTaskQueue(); - ~AsyncTaskQueue(); + virtual ~AsyncTaskQueue(); /*! Adds @c function to the queue. @@ -69,6 +69,8 @@ class AsyncTaskQueue { */ class DeferringAsyncTaskQueue: public AsyncTaskQueue { public: + ~DeferringAsyncTaskQueue(); + /*! Adds a function to the deferral list. diff --git a/Concurrency/BestEffortUpdater.cpp b/Concurrency/BestEffortUpdater.cpp index a3ea15067..96156b742 100644 --- a/Concurrency/BestEffortUpdater.cpp +++ b/Concurrency/BestEffortUpdater.cpp @@ -17,6 +17,11 @@ BestEffortUpdater::BestEffortUpdater() { update_is_ongoing_.clear(); } +BestEffortUpdater::~BestEffortUpdater() { + // Don't allow further deconstruction until the task queue is stopped. + flush(); +} + void BestEffortUpdater::update() { // Perform an update only if one is not currently ongoing. if(!update_is_ongoing_.test_and_set()) { diff --git a/Concurrency/BestEffortUpdater.hpp b/Concurrency/BestEffortUpdater.hpp index 6fb21edc3..c75877dac 100644 --- a/Concurrency/BestEffortUpdater.hpp +++ b/Concurrency/BestEffortUpdater.hpp @@ -26,6 +26,7 @@ namespace Concurrency { class BestEffortUpdater { public: BestEffortUpdater(); + ~BestEffortUpdater(); /// A delegate receives timing cues. struct Delegate { diff --git a/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift b/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift index 0c24166bd..f94963372 100644 --- a/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift +++ b/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift @@ -106,6 +106,7 @@ class MachineDocument: bestEffortLock.lock() bestEffortUpdater!.delegate = nil + bestEffortUpdater!.flush() bestEffortUpdater = nil bestEffortLock.unlock()