1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-02 20:30:00 +00:00

Now that this spin blocks at startup, I can use a standard atomic_flag.

This commit is contained in:
Thomas Harte 2020-06-16 23:12:58 -04:00
parent 17bb3dce26
commit e8939aada4

View File

@ -20,9 +20,9 @@ class FunctionThread: public QThread {
FunctionThread() : QThread() { FunctionThread() : QThread() {
// TODO: I've assumed a race condition here with the creation of performer; if 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. // blocks on completion of `run` when starting then this is redundant.
performerFlag = false; performerFlag.test_and_set();
start(); start();
while(!performerFlag); while(performerFlag.test_and_set());
} }
void run() override { 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 // 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. // posted to an object created on that thread. FunctionPerformer fills that role.
performer = std::make_unique<FunctionPerformer>(); performer = std::make_unique<FunctionPerformer>();
performerFlag = true; performerFlag.clear();
exec(); exec();
} }
@ -75,7 +75,7 @@ class FunctionThread: public QThread {
} }
}; };
std::unique_ptr<FunctionPerformer> performer; std::unique_ptr<FunctionPerformer> performer;
std::atomic<bool> performerFlag; std::atomic_flag performerFlag;
}; };
#endif // FUNCTIONTHREAD_H #endif // FUNCTIONTHREAD_H