diff 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
line wrap: on
line diff
--- a/data/model/SparseOneDimensionalModel.h	Tue Oct 01 11:21:56 2019 +0100
+++ b/data/model/SparseOneDimensionalModel.h	Tue Oct 01 11:22:48 2019 +0100
@@ -89,10 +89,8 @@
 
     void setCompletion(int completion, bool update = true) {
         
-        {   QMutexLocker locker(&m_mutex);
-            if (m_completion == completion) return;
-            m_completion = completion;
-        }
+        if (m_completion == completion) return;
+        m_completion = completion;
 
         if (update) {
             m_notifier.makeDeferredNotifications();
@@ -152,21 +150,17 @@
      */
     void add(Event e) override {
 
-        {   QMutexLocker locker(&m_mutex);
-            m_events.add(e.withoutValue().withoutDuration());
+        m_events.add(e.withoutValue().withoutDuration());
 
-            if (e.getLabel() != "") {
-                m_haveTextLabels = true;
-            }
+        if (e.getLabel() != "") {
+            m_haveTextLabels = true;
         }
         
         m_notifier.update(e.getFrame(), m_resolution);
     }
     
     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);
     }
@@ -311,16 +305,13 @@
     sv_samplerate_t m_sampleRate;
     int m_resolution;
 
-    bool m_haveTextLabels;
+    std::atomic<bool> m_haveTextLabels;
     DeferredNotifier m_notifier;
-    int m_completion;
+    std::atomic<int> m_completion;
 
     EventSeries m_events;
-
-    mutable QMutex m_mutex;  
 };
 
 #endif
 
 
-