From e8939aada47aba6c83af429712d89a23b2bfc586 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 16 Jun 2020 23:12:58 -0400 Subject: [PATCH] Now that this spin blocks at startup, I can use a standard atomic_flag. --- OSBindings/Qt/functionthread.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/OSBindings/Qt/functionthread.h b/OSBindings/Qt/functionthread.h index 575f99614..947787ec2 100644 --- a/OSBindings/Qt/functionthread.h +++ b/OSBindings/Qt/functionthread.h @@ -20,9 +20,9 @@ class FunctionThread: public QThread { FunctionThread() : QThread() { // TODO: I've assumed a race condition here with the creation of performer; if QThread // blocks on completion of `run` when starting then this is redundant. - performerFlag = false; + performerFlag.test_and_set(); start(); - while(!performerFlag); + while(performerFlag.test_and_set()); } void run() override { @@ -30,7 +30,7 @@ class FunctionThread: public QThread { // that created the QThread. To have events occur within a QThread, they have to be // posted to an object created on that thread. FunctionPerformer fills that role. performer = std::make_unique(); - performerFlag = true; + performerFlag.clear(); exec(); } @@ -75,7 +75,7 @@ class FunctionThread: public QThread { } }; std::unique_ptr performer; - std::atomic performerFlag; + std::atomic_flag performerFlag; }; #endif // FUNCTIONTHREAD_H