From 353b9bd32265ca64421a121a5a4c4f7e3ffddfdd Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 7 Apr 2023 17:10:30 +0200 Subject: [PATCH] add some thread safety --- linux/acs/RwPollingTask.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/linux/acs/RwPollingTask.cpp b/linux/acs/RwPollingTask.cpp index d118ba69..39bc28b6 100644 --- a/linux/acs/RwPollingTask.cpp +++ b/linux/acs/RwPollingTask.cpp @@ -47,15 +47,25 @@ ReturnValue_t RwPollingTask::performOperation(uint8_t operationCode) { if (result != returnvalue::OK) { continue; } + acs::SimpleSensorMode currentMode; + rws::SpecialRwRequest specialRequest; + bool doSetSpeed; + for (unsigned idx = 0; idx < rwCookies.size(); idx++) { - if (rwRequests[idx].mode == acs::SimpleSensorMode::OFF) { + { + MutexGuard mg(ipcLock); + currentMode = rwRequests[idx].mode; + specialRequest = rwRequests[idx].specialRequest; + doSetSpeed = rwRequests[idx].setSpeed; + } + if (currentMode == acs::SimpleSensorMode::OFF) { skipCommandingForRw[idx] = true; - } else if (rwRequests[idx].specialRequest == rws::SpecialRwRequest::RESET_MCU) { + } else if (specialRequest == rws::SpecialRwRequest::RESET_MCU) { prepareSimpleCommand(rws::RESET_MCU); // No point in commanding that specific RW for the cycle. skipCommandingForRw[idx] = true; writeOneRwCmd(idx, fd); - } else if (rwRequests[idx].setSpeed) { + } else if (doSetSpeed) { prepareSetSpeedCmd(idx); if (writeOneRwCmd(idx, fd) != returnvalue::OK) { continue;