1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2025-06-26 14:05:33 -04:00

glScope: use atomic variable for the data changed indicator

This commit is contained in:
f4exb 2018-11-20 08:00:19 +01:00
parent af9c693412
commit 02a6cee99f
2 changed files with 17 additions and 15 deletions

View File

@ -33,7 +33,7 @@ GLScope::GLScope(QWidget* parent) :
m_processingTraceIndex(-1), m_processingTraceIndex(-1),
m_bufferIndex(0), m_bufferIndex(0),
m_displayMode(DisplayX), m_displayMode(DisplayX),
m_dataChanged(false), m_dataChanged(0),
m_configChanged(false), m_configChanged(false),
m_sampleRate(0), m_sampleRate(0),
m_timeOfsProMill(0), m_timeOfsProMill(0),
@ -103,11 +103,13 @@ void GLScope::newTraces(std::vector<float *>* traces)
{ {
if (traces->size() > 0) if (traces->size() > 0)
{ {
if(!m_mutex.tryLock(2)) if (!m_mutex.tryLock(2)) {
return; return;
}
if (m_dataChanged.testAndSetOrdered(0, 1)) {
m_traces = traces; m_traces = traces;
m_dataChanged = true; }
m_mutex.unlock(); m_mutex.unlock();
} }
@ -117,12 +119,15 @@ void GLScope::newTraces(std::vector<float *>* traces, int traceIndex)
{ {
if (traces->size() > 0) if (traces->size() > 0)
{ {
if(!m_mutex.tryLock(2)) if(!m_mutex.tryLock(2)) {
return; return;
}
if (m_dataChanged.testAndSetOrdered(0, 1))
{
m_processingTraceIndex.store(traceIndex); m_processingTraceIndex.store(traceIndex);
m_traces = &traces[traceIndex]; m_traces = &traces[traceIndex];
m_dataChanged = true; }
m_mutex.unlock(); m_mutex.unlock();
} }
@ -192,9 +197,7 @@ void GLScope::resizeGL(int width, int height)
void GLScope::paintGL() void GLScope::paintGL()
{ {
if (!m_mutex.tryLock(2)) if (!m_mutex.tryLock(2)) {
{
m_processingTraceIndex.store(-1);
return; return;
} }
@ -205,8 +208,6 @@ void GLScope::paintGL()
// qDebug("GLScope::paintGL: m_traceCounter: %d", m_traceCounter); // qDebug("GLScope::paintGL: m_traceCounter: %d", m_traceCounter);
// m_traceCounter = 0; // m_traceCounter = 0;
m_dataChanged = false;
QOpenGLFunctions *glFunctions = QOpenGLContext::currentContext()->functions(); QOpenGLFunctions *glFunctions = QOpenGLContext::currentContext()->functions();
glFunctions->glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glFunctions->glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glFunctions->glClear(GL_COLOR_BUFFER_BIT); glFunctions->glClear(GL_COLOR_BUFFER_BIT);
@ -940,6 +941,7 @@ void GLScope::paintGL()
} // trace length > 0 } // trace length > 0
} // XY mixed + polar display } // XY mixed + polar display
m_dataChanged.store(0);
m_processingTraceIndex.store(-1); m_processingTraceIndex.store(-1);
m_mutex.unlock(); m_mutex.unlock();
} }
@ -1995,7 +1997,7 @@ void GLScope::drawChannelOverlay(
void GLScope::tick() void GLScope::tick()
{ {
if(m_dataChanged) { if (m_dataChanged.load()) {
update(); update();
} }
} }

View File

@ -95,7 +95,7 @@ private:
DisplayMode m_displayMode; DisplayMode m_displayMode;
QTimer m_timer; QTimer m_timer;
QMutex m_mutex; QMutex m_mutex;
bool m_dataChanged; QAtomicInt m_dataChanged;
bool m_configChanged; bool m_configChanged;
int m_sampleRate; int m_sampleRate;
int m_timeOfsProMill; int m_timeOfsProMill;