1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-22 16:08:39 -05: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;
}
if (m_configChanged) {
if (m_configChanged)
{
applyConfig();
m_configChanged = false;
}
// qDebug("GLScope::paintGL: m_traceCounter: %d", m_traceCounter);
@ -950,26 +952,29 @@ void GLScope::paintGL()
void GLScope::setSampleRate(int sampleRate)
{
QMutexLocker mutexLocker(&m_mutex);
m_mutex.lock();
m_sampleRate = sampleRate;
m_configChanged = true;
m_mutex.unlock();
update();
emit sampleRateChanged(m_sampleRate);
}
void GLScope::setTimeBase(int timeBase)
{
QMutexLocker mutexLocker(&m_mutex);
m_mutex.lock();
m_timeBase = timeBase;
m_configChanged = true;
m_mutex.unlock();
update();
}
void GLScope::setTriggerPre(uint32_t triggerPre, bool emitSignal)
{
QMutexLocker mutexLocker(&m_mutex);
m_mutex.lock();
m_triggerPre = triggerPre;
m_configChanged = true;
m_mutex.unlock();
update();
if (emitSignal) {
@ -979,33 +984,37 @@ void GLScope::setTriggerPre(uint32_t triggerPre, bool emitSignal)
void GLScope::setTimeOfsProMill(int timeOfsProMill)
{
QMutexLocker mutexLocker(&m_mutex);
m_mutex.lock();
m_timeOfsProMill = timeOfsProMill;
m_configChanged = true;
m_mutex.unlock();
update();
}
void GLScope::setFocusedTraceIndex(uint32_t traceIndex)
{
QMutexLocker mutexLocker(&m_mutex);
m_mutex.lock();
m_focusedTraceIndex = traceIndex;
m_configChanged = true;
m_mutex.unlock();
update();
}
void GLScope::setDisplayMode(DisplayMode displayMode)
{
QMutexLocker mutexLocker(&m_mutex);
m_mutex.lock();
m_displayMode = displayMode;
m_configChanged = true;
m_mutex.unlock();
update();
}
void GLScope::setTraceSize(int traceSize, bool emitSignal)
{
QMutexLocker mutexLocker(&m_mutex);
m_mutex.lock();
m_traceSize = traceSize;
m_configChanged = true;
m_mutex.unlock();
update();
if (emitSignal) {
@ -1015,15 +1024,14 @@ void GLScope::setTraceSize(int traceSize, bool emitSignal)
void GLScope::updateDisplay()
{
QMutexLocker mutexLocker(&m_mutex);
m_mutex.lock();
m_configChanged = true;
m_mutex.unlock();
update();
}
void GLScope::applyConfig()
{
m_configChanged = false;
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.0f) * (float) m_traceSize) / m_sampleRate) - ((float) m_triggerPre / m_sampleRate);

View File

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