Mercurial > hg > svcore
comparison data/model/SparseOneDimensionalModel.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 |
comparison
equal
deleted
inserted
replaced
1797:e8b552549225 | 1798:13bd41bd8a17 |
---|---|
87 | 87 |
88 int getCompletion() const override { return m_completion; } | 88 int getCompletion() const override { return m_completion; } |
89 | 89 |
90 void setCompletion(int completion, bool update = true) { | 90 void setCompletion(int completion, bool update = true) { |
91 | 91 |
92 { QMutexLocker locker(&m_mutex); | 92 if (m_completion == completion) return; |
93 if (m_completion == completion) return; | 93 m_completion = completion; |
94 m_completion = completion; | |
95 } | |
96 | 94 |
97 if (update) { | 95 if (update) { |
98 m_notifier.makeDeferredNotifications(); | 96 m_notifier.makeDeferredNotifications(); |
99 } | 97 } |
100 | 98 |
150 /** | 148 /** |
151 * Editing methods. | 149 * Editing methods. |
152 */ | 150 */ |
153 void add(Event e) override { | 151 void add(Event e) override { |
154 | 152 |
155 { QMutexLocker locker(&m_mutex); | 153 m_events.add(e.withoutValue().withoutDuration()); |
156 m_events.add(e.withoutValue().withoutDuration()); | 154 |
157 | 155 if (e.getLabel() != "") { |
158 if (e.getLabel() != "") { | 156 m_haveTextLabels = true; |
159 m_haveTextLabels = true; | |
160 } | |
161 } | 157 } |
162 | 158 |
163 m_notifier.update(e.getFrame(), m_resolution); | 159 m_notifier.update(e.getFrame(), m_resolution); |
164 } | 160 } |
165 | 161 |
166 void remove(Event e) override { | 162 void remove(Event e) override { |
167 { QMutexLocker locker(&m_mutex); | 163 m_events.remove(e); |
168 m_events.remove(e); | |
169 } | |
170 emit modelChangedWithin(getId(), | 164 emit modelChangedWithin(getId(), |
171 e.getFrame(), e.getFrame() + m_resolution); | 165 e.getFrame(), e.getFrame() + m_resolution); |
172 } | 166 } |
173 | 167 |
174 /** | 168 /** |
309 | 303 |
310 protected: | 304 protected: |
311 sv_samplerate_t m_sampleRate; | 305 sv_samplerate_t m_sampleRate; |
312 int m_resolution; | 306 int m_resolution; |
313 | 307 |
314 bool m_haveTextLabels; | 308 std::atomic<bool> m_haveTextLabels; |
315 DeferredNotifier m_notifier; | 309 DeferredNotifier m_notifier; |
316 int m_completion; | 310 std::atomic<int> m_completion; |
317 | 311 |
318 EventSeries m_events; | 312 EventSeries m_events; |
319 | |
320 mutable QMutex m_mutex; | |
321 }; | 313 }; |
322 | 314 |
323 #endif | 315 #endif |
324 | 316 |
325 | 317 |
326 |