From aa10d3b2758acbb3df11379a742ac9662feda971 Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Wed, 21 Feb 2024 10:39:03 +0100 Subject: [PATCH 1/2] Add atomic variable m_coinAttached to check for state change: send signal runProc_coinAttached only if state changes from false true. --- include/runProc.h | 5 +++++ src/runProc.cpp | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/include/runProc.h b/include/runProc.h index c2eb001..4179216 100755 --- a/include/runProc.h +++ b/include/runProc.h @@ -15,6 +15,7 @@ #include #include "datIf.h" #include +#include #include "sendWRcmd.h" #include "controlBus.h" #include "storeINdata.h" @@ -35,6 +36,10 @@ class T_runProc : public QObject void restoreDeviceParameter(struct T_devices *deviceSettings); +#ifndef THIS_IS_CA_MASTER + std::atomic_bool m_coinAttached{false}; +#endif + private slots: void runProc_slotProcess(void); bool bl_performComplStart(void); diff --git a/src/runProc.cpp b/src/runProc.cpp index 1666de8..d7af5e8 100644 --- a/src/runProc.cpp +++ b/src/runProc.cpp @@ -48,8 +48,12 @@ T_runProc::T_runProc() void T_runProc::runProc_slotProcess(void) { #ifndef THIS_IS_CA_MASTER - if (epi_getDI_CoinAttach()) { - emit runProc_coinAttached(); + bool const coinAttached = epi_getDI_CoinAttach(); + if (m_coinAttached.exchange(coinAttached) == false) { + if (coinAttached) { + // old value was false, and new value is true + emit runProc_coinAttached(); + } } cash_paymentProcessing(); doors_supervise(); From 9cac6a6461d3da607f6495bbec46fe8537340e3b Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Wed, 21 Feb 2024 10:46:34 +0100 Subject: [PATCH 2/2] Added comment for std::atomic::exchange() --- src/runProc.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/runProc.cpp b/src/runProc.cpp index d7af5e8..a7783d8 100644 --- a/src/runProc.cpp +++ b/src/runProc.cpp @@ -49,6 +49,9 @@ void T_runProc::runProc_slotProcess(void) { #ifndef THIS_IS_CA_MASTER bool const coinAttached = epi_getDI_CoinAttach(); + // exchange: (atomically) replaces the underlying value of m_coinAttached + // with the value of coinAttached, returns the value of m_coinAttached + // before the call if (m_coinAttached.exchange(coinAttached) == false) { if (coinAttached) { // old value was false, and new value is true