Mercurial > hg > svcore
diff data/model/SparseTimeValueModel.h @ 1798:13bd41bd8a17
Some work on making Model classes thread-safe in typical use - and documenting this. Some of the implementations are simpler now that EventSeries is thread-safe
author | Chris Cannam |
---|---|
date | Tue, 01 Oct 2019 11:22:48 +0100 |
parents | 6d09d68165a4 |
children | 343ef2a866a4 |
line wrap: on
line diff
--- a/data/model/SparseTimeValueModel.h Tue Oct 01 11:21:56 2019 +0100 +++ b/data/model/SparseTimeValueModel.h Tue Oct 01 11:22:48 2019 +0100 @@ -105,8 +105,12 @@ bool canPlay() const override { return true; } bool getDefaultPlayAudible() const override { return false; } // user must unmute - QString getScaleUnits() const { return m_units; } + QString getScaleUnits() const { + QMutexLocker locker(&m_mutex); + return m_units; + } void setScaleUnits(QString units) { + QMutexLocker locker(&m_mutex); m_units = units; UnitDatabase::getInstance()->registerUnit(units); } @@ -120,7 +124,7 @@ void setCompletion(int completion, bool update = true) { - { QMutexLocker locker(&m_mutex); + { if (m_completion == completion) return; m_completion = completion; } @@ -185,23 +189,21 @@ bool allChange = false; - { QMutexLocker locker(&m_mutex); - m_events.add(e.withoutDuration()); // can't have duration here + m_events.add(e.withoutDuration()); // can't have duration here - if (e.getLabel() != "") { - m_haveTextLabels = true; + if (e.getLabel() != "") { + m_haveTextLabels = true; + } + + float v = e.getValue(); + if (!ISNAN(v) && !ISINF(v)) { + if (!m_haveExtents || v < m_valueMinimum) { + m_valueMinimum = v; allChange = true; } - - float v = e.getValue(); - if (!ISNAN(v) && !ISINF(v)) { - if (!m_haveExtents || v < m_valueMinimum) { - m_valueMinimum = v; allChange = true; - } - if (!m_haveExtents || v > m_valueMaximum) { - m_valueMaximum = v; allChange = true; - } - m_haveExtents = true; + if (!m_haveExtents || v > m_valueMaximum) { + m_valueMaximum = v; allChange = true; } + m_haveExtents = true; } m_notifier.update(e.getFrame(), m_resolution); @@ -212,10 +214,7 @@ } void remove(Event e) override { - { - QMutexLocker locker(&m_mutex); - m_events.remove(e); - } + m_events.remove(e); emit modelChangedWithin(getId(), e.getFrame(), e.getFrame() + m_resolution); } @@ -344,20 +343,17 @@ sv_samplerate_t m_sampleRate; int m_resolution; - float m_valueMinimum; - float m_valueMaximum; - bool m_haveExtents; - bool m_haveTextLabels; + std::atomic<float> m_valueMinimum; + std::atomic<float> m_valueMaximum; + std::atomic<bool> m_haveExtents; + std::atomic<bool> m_haveTextLabels; QString m_units; DeferredNotifier m_notifier; - int m_completion; + std::atomic<int> m_completion; EventSeries m_events; - - mutable QMutex m_mutex; }; - #endif