1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-01-26 15:32:04 +00:00

Installs additional safeguards against unsafe deconstruction.

This commit is contained in:
Thomas Harte 2018-02-28 22:15:22 -05:00
parent 87760297fc
commit 83f73c3f02
5 changed files with 14 additions and 1 deletions

View File

@ -80,6 +80,10 @@ void AsyncTaskQueue::flush() {
#endif
}
DeferringAsyncTaskQueue::~DeferringAsyncTaskQueue() {
perform();
}
void DeferringAsyncTaskQueue::defer(std::function<void(void)> function) {
if(!deferred_tasks_) {
deferred_tasks_.reset(new std::list<std::function<void(void)>>);

View File

@ -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.

View File

@ -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()) {

View File

@ -26,6 +26,7 @@ namespace Concurrency {
class BestEffortUpdater {
public:
BestEffortUpdater();
~BestEffortUpdater();
/// A delegate receives timing cues.
struct Delegate {

View File

@ -106,6 +106,7 @@ class MachineDocument:
bestEffortLock.lock()
bestEffortUpdater!.delegate = nil
bestEffortUpdater!.flush()
bestEffortUpdater = nil
bestEffortLock.unlock()