From 02a6cee99fdb0cd8c19d2f89d0b04c7f4af1f45c Mon Sep 17 00:00:00 2001 From: f4exb Date: Tue, 20 Nov 2018 08:00:19 +0100 Subject: [PATCH] glScope: use atomic variable for the data changed indicator --- sdrgui/gui/glscope.cpp | 30 ++++++++++++++++-------------- sdrgui/gui/glscope.h | 2 +- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/sdrgui/gui/glscope.cpp b/sdrgui/gui/glscope.cpp index bdba1e1eb..6cb63c444 100644 --- a/sdrgui/gui/glscope.cpp +++ b/sdrgui/gui/glscope.cpp @@ -33,7 +33,7 @@ GLScope::GLScope(QWidget* parent) : m_processingTraceIndex(-1), m_bufferIndex(0), m_displayMode(DisplayX), - m_dataChanged(false), + m_dataChanged(0), m_configChanged(false), m_sampleRate(0), m_timeOfsProMill(0), @@ -103,11 +103,13 @@ void GLScope::newTraces(std::vector* traces) { if (traces->size() > 0) { - if(!m_mutex.tryLock(2)) + if (!m_mutex.tryLock(2)) { return; + } - m_traces = traces; - m_dataChanged = true; + if (m_dataChanged.testAndSetOrdered(0, 1)) { + m_traces = traces; + } m_mutex.unlock(); } @@ -117,12 +119,15 @@ void GLScope::newTraces(std::vector* traces, int traceIndex) { if (traces->size() > 0) { - if(!m_mutex.tryLock(2)) + if(!m_mutex.tryLock(2)) { return; + } - m_processingTraceIndex.store(traceIndex); - m_traces = &traces[traceIndex]; - m_dataChanged = true; + if (m_dataChanged.testAndSetOrdered(0, 1)) + { + m_processingTraceIndex.store(traceIndex); + m_traces = &traces[traceIndex]; + } m_mutex.unlock(); } @@ -192,9 +197,7 @@ void GLScope::resizeGL(int width, int height) void GLScope::paintGL() { - if (!m_mutex.tryLock(2)) - { - m_processingTraceIndex.store(-1); + if (!m_mutex.tryLock(2)) { return; } @@ -205,8 +208,6 @@ void GLScope::paintGL() // qDebug("GLScope::paintGL: m_traceCounter: %d", m_traceCounter); // m_traceCounter = 0; - m_dataChanged = false; - QOpenGLFunctions *glFunctions = QOpenGLContext::currentContext()->functions(); glFunctions->glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glFunctions->glClear(GL_COLOR_BUFFER_BIT); @@ -940,6 +941,7 @@ void GLScope::paintGL() } // trace length > 0 } // XY mixed + polar display + m_dataChanged.store(0); m_processingTraceIndex.store(-1); m_mutex.unlock(); } @@ -1995,7 +1997,7 @@ void GLScope::drawChannelOverlay( void GLScope::tick() { - if(m_dataChanged) { + if (m_dataChanged.load()) { update(); } } diff --git a/sdrgui/gui/glscope.h b/sdrgui/gui/glscope.h index 6120a2217..c93ed46d7 100644 --- a/sdrgui/gui/glscope.h +++ b/sdrgui/gui/glscope.h @@ -95,7 +95,7 @@ private: DisplayMode m_displayMode; QTimer m_timer; QMutex m_mutex; - bool m_dataChanged; + QAtomicInt m_dataChanged; bool m_configChanged; int m_sampleRate; int m_timeOfsProMill;