comparison data/model/ImageModel.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
74 74
75 int getCompletion() const override { return m_completion; } 75 int getCompletion() const override { return m_completion; }
76 76
77 void setCompletion(int completion, bool update = true) { 77 void setCompletion(int completion, bool update = true) {
78 78
79 { QMutexLocker locker(&m_mutex); 79 if (m_completion == completion) return;
80 if (m_completion == completion) return; 80 m_completion = completion;
81 m_completion = completion;
82 }
83 81
84 if (update) { 82 if (update) {
85 m_notifier.makeDeferredNotifications(); 83 m_notifier.makeDeferredNotifications();
86 } 84 }
87 85
139 137
140 /** 138 /**
141 * Editing methods. 139 * Editing methods.
142 */ 140 */
143 void add(Event e) override { 141 void add(Event e) override {
144 142 m_events.add(e.withoutDuration().withoutValue().withoutLevel());
145 { QMutexLocker locker(&m_mutex);
146 m_events.add(e.withoutDuration().withoutValue().withoutLevel());
147 }
148
149 m_notifier.update(e.getFrame(), m_resolution); 143 m_notifier.update(e.getFrame(), m_resolution);
150 } 144 }
151 145
152 void remove(Event e) override { 146 void remove(Event e) override {
153 { QMutexLocker locker(&m_mutex); 147 m_events.remove(e);
154 m_events.remove(e);
155 }
156 emit modelChangedWithin(getId(), 148 emit modelChangedWithin(getId(),
157 e.getFrame(), e.getFrame() + m_resolution); 149 e.getFrame(), e.getFrame() + m_resolution);
158 } 150 }
159 151
160 /** 152 /**
279 protected: 271 protected:
280 sv_samplerate_t m_sampleRate; 272 sv_samplerate_t m_sampleRate;
281 int m_resolution; 273 int m_resolution;
282 274
283 DeferredNotifier m_notifier; 275 DeferredNotifier m_notifier;
284 int m_completion; 276 std::atomic<int> m_completion;
285 277
286 EventSeries m_events; 278 EventSeries m_events;
287
288 mutable QMutex m_mutex;
289 }; 279 };
290 280
291 281
292 #endif 282 #endif
293 283