From 324a3271a4ed44c9d3960f16107889a8ac2f94de Mon Sep 17 00:00:00 2001 From: Robin Getz Date: Sun, 6 Sep 2026 23:57:34 -0400 Subject: [PATCH] adsbdemodsink: Protect magnitude statistics with mutex ADSBDemodSink::processOneSample() updates m_magsqSum, m_magsqPeak, and m_magsqCount from the sample processing path, while getMagSqLevels() reads and updates the same statistics when the GUI requests the current magnitude levels. Thus, two different threads can read and write the same variables concurrently. Protect both access paths with a new m_magsqMutex to prevent concurrent updates and reads of the magnitude statistics. This eliminates the data race identified by ThreadSanitizer and prevents the GUI from observing partially updated magnitude statistics while ADS-B samples are being processed. Signed-off-by: Robin Getz --- plugins/channelrx/demodadsb/adsbdemodsink.cpp | 12 ++++++++---- plugins/channelrx/demodadsb/adsbdemodsink.h | 4 ++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/plugins/channelrx/demodadsb/adsbdemodsink.cpp b/plugins/channelrx/demodadsb/adsbdemodsink.cpp index fa599f1e0..024643769 100644 --- a/plugins/channelrx/demodadsb/adsbdemodsink.cpp +++ b/plugins/channelrx/demodadsb/adsbdemodsink.cpp @@ -121,10 +121,14 @@ void ADSBDemodSink::feed(const SampleVector::const_iterator& begin, const Sample void ADSBDemodSink::processOneSample(Real magsq) { - m_magsqSum += magsq; - if (magsq > m_magsqPeak) - m_magsqPeak = magsq; - m_magsqCount++; + { + QMutexLocker locker(&m_magsqMutex); + + m_magsqSum += magsq; + if (magsq > m_magsqPeak) + m_magsqPeak = magsq; + m_magsqCount++; + } m_sampleBuffer[m_writeBuffer][m_writeIdx] = magsq; m_writeIdx++; if (!m_bufferDateTimeValid[m_writeBuffer]) diff --git a/plugins/channelrx/demodadsb/adsbdemodsink.h b/plugins/channelrx/demodadsb/adsbdemodsink.h index c57e312d5..fc458bf25 100644 --- a/plugins/channelrx/demodadsb/adsbdemodsink.h +++ b/plugins/channelrx/demodadsb/adsbdemodsink.h @@ -35,6 +35,8 @@ public: void getMagSqLevels(double& avg, double& peak, int& nbSamples) { + QMutexLocker locker(&m_magsqMutex); + if (m_magsqCount > 0) { m_magsq = m_magsqSum / m_magsqCount; @@ -107,6 +109,8 @@ private: int m_magsqCount; MagSqLevelsStore m_magSqLevelStore; + QMutex m_magsqMutex; + MessageQueue *m_messageQueueToGUI; MessageQueue *m_messageQueueToWorker;