From c8a29bb40096de3fd4b77d7c7f218531a1372647 Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Fri, 10 Feb 2023 15:23:57 +0000 Subject: [PATCH] Add mutex to ensure thread safety --- controllersetup.cpp | 14 +++++++++++++- controllersetup.h | 4 ++-- usbcontroller.cpp | 15 ++++++++++----- usbcontroller.h | 6 ++++-- wfmain.cpp | 16 +++++++++++----- wfmain.h | 3 ++- 6 files changed, 42 insertions(+), 16 deletions(-) diff --git a/controllersetup.cpp b/controllersetup.cpp index 32daa50..336a3cb 100644 --- a/controllersetup.cpp +++ b/controllersetup.cpp @@ -70,6 +70,9 @@ void controllerSetup::mousePressed(QPoint p) } bool found = false; + QMutexLocker locker(mutex); + + for (BUTTON& b : *buttons) { if (b.dev == currentDevice && b.pos.contains(p)) @@ -119,20 +122,25 @@ void controllerSetup::mousePressed(QPoint p) offEvent->hide(); knobEvent->hide(); } + } void controllerSetup::onEventIndexChanged(int index) { Q_UNUSED(index); + if (currentButton != Q_NULLPTR && onEvent->currentData().toInt() < commands->size()) { + QMutexLocker locker(mutex); currentButton->onCommand = &commands->at(onEvent->currentData().toInt()); currentButton->onText->setPlainText(currentButton->onCommand->text); } + } void controllerSetup::offEventIndexChanged(int index) { Q_UNUSED(index); if (currentButton != Q_NULLPTR && offEvent->currentData().toInt() < commands->size()) { + QMutexLocker locker(mutex); currentButton->offCommand = &commands->at(offEvent->currentData().toInt()); currentButton->offText->setPlainText(currentButton->offCommand->text); } @@ -141,17 +149,21 @@ void controllerSetup::offEventIndexChanged(int index) { void controllerSetup::knobEventIndexChanged(int index) { Q_UNUSED(index); if (currentKnob != Q_NULLPTR && knobEvent->currentData().toInt() < commands->size()) { + QMutexLocker locker(mutex); currentKnob->command = &commands->at(knobEvent->currentData().toInt()); currentKnob->text->setPlainText(currentKnob->command->text); } } -void controllerSetup::newDevice(unsigned char devType, QVector