From e88c7b29ea9ec9fcd6ac6b15c965085152100d2e Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 18 Jun 2017 18:19:17 +0200 Subject: get rid of "volatile" abuse We heavily used "volatile bool" to check if the thread loop should stop. But this functionality is already provided by Qt5's QThread::requestInterruption. In other cases, "volatile" is wonderfully underspecified so it's better to ditch its usage in favor of std::atomic. At the time we don't appear to be using the "volatile" keyword except when calling win32's Interlocked*() family of functions as necessary. In freetrackclient's header the "volatile" qualifier was used as part of a typedef. This doesn't work. Use it as part of data declaration. --- dinput/keybinding-worker.cpp | 11 +++++------ dinput/keybinding-worker.hpp | 1 - 2 files changed, 5 insertions(+), 7 deletions(-) (limited to 'dinput') diff --git a/dinput/keybinding-worker.cpp b/dinput/keybinding-worker.cpp index 0357752c..41fa3486 100644 --- a/dinput/keybinding-worker.cpp +++ b/dinput/keybinding-worker.cpp @@ -28,7 +28,7 @@ KeybindingWorker::~KeybindingWorker() { qDebug() << "exit: keybinding worker"; - should_quit = true; + requestInterruption(); wait(); if (dinkeyboard) { dinkeyboard->Unacquire(); @@ -74,11 +74,10 @@ bool KeybindingWorker::init() return true; } -KeybindingWorker::KeybindingWorker() : dinkeyboard(nullptr), din(dinput_handle::make_di()), should_quit(false) +KeybindingWorker::KeybindingWorker() : dinkeyboard(nullptr), din(dinput_handle::make_di()) { - should_quit = !init(); - - start(); + if (init()) + start(); } KeybindingWorker& KeybindingWorker::make() @@ -92,7 +91,7 @@ void KeybindingWorker::run() unsigned char keystate[256] = {0}; unsigned char old_keystate[256] = {0}; - while (!should_quit) + while (!isInterruptionRequested()) { { QMutexLocker l(&mtx); diff --git a/dinput/keybinding-worker.hpp b/dinput/keybinding-worker.hpp index 553a314c..6ed277cd 100644 --- a/dinput/keybinding-worker.hpp +++ b/dinput/keybinding-worker.hpp @@ -48,7 +48,6 @@ private: QMutex mtx; QMainWindow fake_main_window; dinput_handle::di_t din; - volatile bool should_quit; void run() override; bool init(); -- cgit v1.2.3