1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2025-09-03 13:47:50 -04:00

GLSpectrum and GLScope: do not leave mutex locked while calling the update() method. Reset the config changed flag after call to applyConfig()

This commit is contained in:
f4exb 2019-08-23 13:23:19 +02:00
parent 1decab31a9
commit ac8a73c529
2 changed files with 63 additions and 36 deletions

View File

@ -203,8 +203,10 @@ void GLScope::paintGL()
return; return;
} }
if (m_configChanged) { if (m_configChanged)
{
applyConfig(); applyConfig();
m_configChanged = false;
} }
// qDebug("GLScope::paintGL: m_traceCounter: %d", m_traceCounter); // qDebug("GLScope::paintGL: m_traceCounter: %d", m_traceCounter);
@ -950,26 +952,29 @@ void GLScope::paintGL()
void GLScope::setSampleRate(int sampleRate) void GLScope::setSampleRate(int sampleRate)
{ {
QMutexLocker mutexLocker(&m_mutex); m_mutex.lock();
m_sampleRate = sampleRate; m_sampleRate = sampleRate;
m_configChanged = true; m_configChanged = true;
m_mutex.unlock();
update(); update();
emit sampleRateChanged(m_sampleRate); emit sampleRateChanged(m_sampleRate);
} }
void GLScope::setTimeBase(int timeBase) void GLScope::setTimeBase(int timeBase)
{ {
QMutexLocker mutexLocker(&m_mutex); m_mutex.lock();
m_timeBase = timeBase; m_timeBase = timeBase;
m_configChanged = true; m_configChanged = true;
m_mutex.unlock();
update(); update();
} }
void GLScope::setTriggerPre(uint32_t triggerPre, bool emitSignal) void GLScope::setTriggerPre(uint32_t triggerPre, bool emitSignal)
{ {
QMutexLocker mutexLocker(&m_mutex); m_mutex.lock();
m_triggerPre = triggerPre; m_triggerPre = triggerPre;
m_configChanged = true; m_configChanged = true;
m_mutex.unlock();
update(); update();
if (emitSignal) { if (emitSignal) {
@ -979,33 +984,37 @@ void GLScope::setTriggerPre(uint32_t triggerPre, bool emitSignal)
void GLScope::setTimeOfsProMill(int timeOfsProMill) void GLScope::setTimeOfsProMill(int timeOfsProMill)
{ {
QMutexLocker mutexLocker(&m_mutex); m_mutex.lock();
m_timeOfsProMill = timeOfsProMill; m_timeOfsProMill = timeOfsProMill;
m_configChanged = true; m_configChanged = true;
m_mutex.unlock();
update(); update();
} }
void GLScope::setFocusedTraceIndex(uint32_t traceIndex) void GLScope::setFocusedTraceIndex(uint32_t traceIndex)
{ {
QMutexLocker mutexLocker(&m_mutex); m_mutex.lock();
m_focusedTraceIndex = traceIndex; m_focusedTraceIndex = traceIndex;
m_configChanged = true; m_configChanged = true;
m_mutex.unlock();
update(); update();
} }
void GLScope::setDisplayMode(DisplayMode displayMode) void GLScope::setDisplayMode(DisplayMode displayMode)
{ {
QMutexLocker mutexLocker(&m_mutex); m_mutex.lock();
m_displayMode = displayMode; m_displayMode = displayMode;
m_configChanged = true; m_configChanged = true;
m_mutex.unlock();
update(); update();
} }
void GLScope::setTraceSize(int traceSize, bool emitSignal) void GLScope::setTraceSize(int traceSize, bool emitSignal)
{ {
QMutexLocker mutexLocker(&m_mutex); m_mutex.lock();
m_traceSize = traceSize; m_traceSize = traceSize;
m_configChanged = true; m_configChanged = true;
m_mutex.unlock();
update(); update();
if (emitSignal) { if (emitSignal) {
@ -1015,15 +1024,14 @@ void GLScope::setTraceSize(int traceSize, bool emitSignal)
void GLScope::updateDisplay() void GLScope::updateDisplay()
{ {
QMutexLocker mutexLocker(&m_mutex); m_mutex.lock();
m_configChanged = true; m_configChanged = true;
m_mutex.unlock();
update(); update();
} }
void GLScope::applyConfig() void GLScope::applyConfig()
{ {
m_configChanged = false;
QFontMetrics fm(font()); QFontMetrics fm(font());
//float t_start = ((m_timeOfsProMill / 1000.0) * ((float) m_traceSize / m_sampleRate)) - ((float) m_triggerPre / m_sampleRate); //float t_start = ((m_timeOfsProMill / 1000.0) * ((float) m_traceSize / m_sampleRate)) - ((float) m_triggerPre / m_sampleRate);
float t_start = (((m_timeOfsProMill / 1000.0f) * (float) m_traceSize) / m_sampleRate) - ((float) m_triggerPre / m_sampleRate); float t_start = (((m_timeOfsProMill / 1000.0f) * (float) m_traceSize) / m_sampleRate) - ((float) m_triggerPre / m_sampleRate);

View File

@ -156,8 +156,6 @@ GLSpectrum::~GLSpectrum()
QMutexLocker mutexLocker(&m_mutex); QMutexLocker mutexLocker(&m_mutex);
m_changesPending = true;
if(m_waterfallBuffer != NULL) { if(m_waterfallBuffer != NULL) {
delete m_waterfallBuffer; delete m_waterfallBuffer;
m_waterfallBuffer = NULL; m_waterfallBuffer = NULL;
@ -174,25 +172,28 @@ GLSpectrum::~GLSpectrum()
void GLSpectrum::setCenterFrequency(qint64 frequency) void GLSpectrum::setCenterFrequency(qint64 frequency)
{ {
QMutexLocker mutexLocker(&m_mutex); m_mutex.lock();
m_centerFrequency = frequency; m_centerFrequency = frequency;
m_changesPending = true; m_changesPending = true;
m_mutex.unlock();
update(); update();
} }
void GLSpectrum::setReferenceLevel(Real referenceLevel) void GLSpectrum::setReferenceLevel(Real referenceLevel)
{ {
QMutexLocker mutexLocker(&m_mutex); m_mutex.lock();
m_referenceLevel = referenceLevel; m_referenceLevel = referenceLevel;
m_changesPending = true; m_changesPending = true;
m_mutex.unlock();
update(); update();
} }
void GLSpectrum::setPowerRange(Real powerRange) void GLSpectrum::setPowerRange(Real powerRange)
{ {
QMutexLocker mutexLocker(&m_mutex); m_mutex.lock();
m_powerRange = powerRange; m_powerRange = powerRange;
m_changesPending = true; m_changesPending = true;
m_mutex.unlock();
update(); update();
} }
@ -213,29 +214,32 @@ void GLSpectrum::setHistoStroke(int stroke)
void GLSpectrum::setSampleRate(qint32 sampleRate) void GLSpectrum::setSampleRate(qint32 sampleRate)
{ {
QMutexLocker mutexLocker(&m_mutex); m_mutex.lock();
m_sampleRate = sampleRate; m_sampleRate = sampleRate;
if (m_messageQueueToGUI) { if (m_messageQueueToGUI) {
m_messageQueueToGUI->push(new MsgReportSampleRate(m_sampleRate)); m_messageQueueToGUI->push(new MsgReportSampleRate(m_sampleRate));
} }
m_changesPending = true; m_changesPending = true;
m_mutex.unlock();
update(); update();
} }
void GLSpectrum::setTimingRate(qint32 timingRate) void GLSpectrum::setTimingRate(qint32 timingRate)
{ {
QMutexLocker mutexLocker(&m_mutex); m_mutex.lock();
m_timingRate = timingRate; m_timingRate = timingRate;
m_changesPending = true; m_changesPending = true;
m_mutex.unlock();
update(); update();
} }
void GLSpectrum::setDisplayWaterfall(bool display) void GLSpectrum::setDisplayWaterfall(bool display)
{ {
QMutexLocker mutexLocker(&m_mutex); m_mutex.lock();
m_displayWaterfall = display; m_displayWaterfall = display;
m_changesPending = true; m_changesPending = true;
stopDrag(); stopDrag();
m_mutex.unlock();
update(); update();
} }
@ -253,37 +257,41 @@ void GLSpectrum::setLsbDisplay(bool lsbDisplay)
void GLSpectrum::setInvertedWaterfall(bool inv) void GLSpectrum::setInvertedWaterfall(bool inv)
{ {
QMutexLocker mutexLocker(&m_mutex); m_mutex.lock();
m_invertedWaterfall = inv; m_invertedWaterfall = inv;
m_changesPending = true; m_changesPending = true;
stopDrag(); stopDrag();
m_mutex.unlock();
update(); update();
} }
void GLSpectrum::setDisplayMaxHold(bool display) void GLSpectrum::setDisplayMaxHold(bool display)
{ {
QMutexLocker mutexLocker(&m_mutex); m_mutex.lock();
m_displayMaxHold = display; m_displayMaxHold = display;
m_changesPending = true; m_changesPending = true;
stopDrag(); stopDrag();
m_mutex.unlock();
update(); update();
} }
void GLSpectrum::setDisplayCurrent(bool display) void GLSpectrum::setDisplayCurrent(bool display)
{ {
QMutexLocker mutexLocker(&m_mutex); m_mutex.lock();
m_displayCurrent = display; m_displayCurrent = display;
m_changesPending = true; m_changesPending = true;
stopDrag(); stopDrag();
m_mutex.unlock();
update(); update();
} }
void GLSpectrum::setDisplayHistogram(bool display) void GLSpectrum::setDisplayHistogram(bool display)
{ {
QMutexLocker mutexLocker(&m_mutex); m_mutex.lock();
m_displayHistogram = display; m_displayHistogram = display;
m_changesPending = true; m_changesPending = true;
stopDrag(); stopDrag();
m_mutex.unlock();
update(); update();
} }
@ -317,38 +325,44 @@ void GLSpectrum::setDisplayTraceIntensity(int intensity)
void GLSpectrum::setLinear(bool linear) void GLSpectrum::setLinear(bool linear)
{ {
QMutexLocker mutexLocker(&m_mutex); m_mutex.lock();
m_linear = linear; m_linear = linear;
m_changesPending = true; m_changesPending = true;
m_mutex.unlock();
update(); update();
} }
void GLSpectrum::addChannelMarker(ChannelMarker* channelMarker) void GLSpectrum::addChannelMarker(ChannelMarker* channelMarker)
{ {
QMutexLocker mutexLocker(&m_mutex); m_mutex.lock();
connect(channelMarker, SIGNAL(changedByAPI()), this, SLOT(channelMarkerChanged())); connect(channelMarker, SIGNAL(changedByAPI()), this, SLOT(channelMarkerChanged()));
connect(channelMarker, SIGNAL(destroyed(QObject*)), this, SLOT(channelMarkerDestroyed(QObject*))); connect(channelMarker, SIGNAL(destroyed(QObject*)), this, SLOT(channelMarkerDestroyed(QObject*)));
m_channelMarkerStates.append(new ChannelMarkerState(channelMarker)); m_channelMarkerStates.append(new ChannelMarkerState(channelMarker));
m_changesPending = true; m_changesPending = true;
stopDrag(); stopDrag();
m_mutex.unlock();
update(); update();
} }
void GLSpectrum::removeChannelMarker(ChannelMarker* channelMarker) void GLSpectrum::removeChannelMarker(ChannelMarker* channelMarker)
{ {
QMutexLocker mutexLocker(&m_mutex); m_mutex.lock();
for(int i = 0; i < m_channelMarkerStates.size(); ++i) { for (int i = 0; i < m_channelMarkerStates.size(); ++i)
if(m_channelMarkerStates[i]->m_channelMarker == channelMarker) { {
if (m_channelMarkerStates[i]->m_channelMarker == channelMarker)
{
channelMarker->disconnect(this); channelMarker->disconnect(this);
delete m_channelMarkerStates.takeAt(i); delete m_channelMarkerStates.takeAt(i);
m_changesPending = true; m_changesPending = true;
stopDrag(); stopDrag();
m_mutex.unlock();
update(); update();
return; return;
} }
} }
m_mutex.unlock();
} }
void GLSpectrum::newSpectrum(const std::vector<Real>& spectrum, int fftSize) void GLSpectrum::newSpectrum(const std::vector<Real>& spectrum, int fftSize)
@ -546,8 +560,9 @@ void GLSpectrum::resizeGL(int width, int height)
void GLSpectrum::clearSpectrumHistogram() void GLSpectrum::clearSpectrumHistogram()
{ {
if(!m_mutex.tryLock(2)) if (!m_mutex.tryLock(2)) {
return; return;
}
memset(m_histogram, 0x00, 100 * m_fftSize); memset(m_histogram, 0x00, 100 * m_fftSize);
@ -557,13 +572,18 @@ void GLSpectrum::clearSpectrumHistogram()
void GLSpectrum::paintGL() void GLSpectrum::paintGL()
{ {
if(!m_mutex.tryLock(2)) if (!m_mutex.tryLock(2)) {
return; return;
}
if(m_changesPending) if (m_changesPending)
{
applyChanges(); applyChanges();
m_changesPending = false;
}
if(m_fftSize <= 0) { if (m_fftSize <= 0)
{
m_mutex.unlock(); m_mutex.unlock();
return; return;
} }
@ -1042,10 +1062,9 @@ void GLSpectrum::stopDrag()
void GLSpectrum::applyChanges() void GLSpectrum::applyChanges()
{ {
m_changesPending = false; if (m_fftSize <= 0) {
if(m_fftSize <= 0)
return; return;
}
QFontMetrics fm(font()); QFontMetrics fm(font());
int M = fm.width("-"); int M = fm.width("-");