]> sigrok.org Git - pulseview.git/commitdiff
Used a std::atomic for StoreSession::_units_stores and _unit_count
authorJoel Holdsworth <redacted>
Fri, 23 May 2014 22:22:37 +0000 (23:22 +0100)
committerJoel Holdsworth <redacted>
Sat, 24 May 2014 08:10:08 +0000 (09:10 +0100)
pv/dialogs/storeprogress.cpp
pv/storesession.cpp
pv/storesession.h

index bbb3881f5810c0907f2ce3efbb33148457e16a57..ecda1d0ec7c680ae1ec72f08011fa830deafa65c 100644 (file)
@@ -69,17 +69,15 @@ void StoreProgress::on_progress_updated()
        const std::pair<uint64_t, uint64_t> p = _session.progress();
        assert(p.first <= p.second);
 
-       setValue(p.first);
-       setMaximum(p.second);
-
-       const QString err = _session.error();
-       if (!err.isEmpty()) {
-               show_error();
+       if (p.second) {
+               setValue(p.first);
+               setMaximum(p.second);
+       } else {
+               const QString err = _session.error();
+               if (!err.isEmpty())
+                       show_error();
                close();
        }
-
-       if (p.first == p.second)
-               close();
 }
 
 } // dialogs
index fcba344e9fa8470b6372119eb26e552f83d312ae..a97513433b9aa6601f7c13ced9e08e569b94ebc9 100644 (file)
@@ -59,8 +59,7 @@ StoreSession::~StoreSession()
 
 pair<uint64_t, uint64_t> StoreSession::progress() const
 {
-       lock_guard<mutex> lock(_mutex);
-       return make_pair(_units_stored, _unit_count);
+       return make_pair(_units_stored.load(), _unit_count.load());
 }
 
 const QString& StoreSession::error() const
@@ -158,10 +157,7 @@ void StoreSession::store_proc(shared_ptr<data::LogicSnapshot> snapshot)
        const int unit_size = snapshot->unit_size();
        assert(unit_size != 0);
 
-       {
-               lock_guard<mutex> lock(_mutex);
-               _unit_count = snapshot->get_sample_count();
-       }
+       _unit_count = snapshot->get_sample_count();
 
        const unsigned int samples_per_block = BlockSize / unit_size;
 
@@ -170,7 +166,7 @@ void StoreSession::store_proc(shared_ptr<data::LogicSnapshot> snapshot)
                progress_updated();
 
                const uint64_t end_sample = min(
-                       start_sample + samples_per_block, _unit_count);
+                       start_sample + samples_per_block, _unit_count.load());
                snapshot->get_samples(data, start_sample, end_sample);
 
                if(sr_session_append(_file_name.c_str(), data, unit_size,
@@ -181,13 +177,10 @@ void StoreSession::store_proc(shared_ptr<data::LogicSnapshot> snapshot)
                }
 
                start_sample = end_sample;
-
-               {
-                       lock_guard<mutex> lock(_mutex);
-                       _units_stored = start_sample;
-               }
+               _units_stored = start_sample;
        }
 
+       _unit_count = 0;
        progress_updated();
 
        delete[] data;
index 4c9eae0160d7588a3543062528610d775dea0d3c..262eddc1eff3a9ad92afef0d673aa85bcb94d5f2 100644 (file)
@@ -75,9 +75,9 @@ private:
 
        std::atomic<bool> _interrupt;
 
+       std::atomic<uint64_t> _units_stored, _unit_count;
+
        mutable std::mutex _mutex;
-       uint64_t _units_stored;
-       uint64_t _unit_count;
        QString _error;
 };