Browse Source

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 <rgetz503@gmail.com>
chirpmodem-v8.0.0
Robin Getz 3 months ago
parent
commit
324a3271a4
No known key found for this signature in database
GPG Key ID: 51C7231FFED0E060
  1. 12
      plugins/channelrx/demodadsb/adsbdemodsink.cpp
  2. 4
      plugins/channelrx/demodadsb/adsbdemodsink.h

12
plugins/channelrx/demodadsb/adsbdemodsink.cpp

@ -121,10 +121,14 @@ void ADSBDemodSink::feed(const SampleVector::const_iterator& begin, const Sample @@ -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])

4
plugins/channelrx/demodadsb/adsbdemodsink.h

@ -35,6 +35,8 @@ public: @@ -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: @@ -107,6 +109,8 @@ private:
int m_magsqCount;
MagSqLevelsStore m_magSqLevelStore;
QMutex m_magsqMutex;
MessageQueue *m_messageQueueToGUI;
MessageQueue *m_messageQueueToWorker;

Loading…
Cancel
Save