From: Joel Holdsworth Date: Fri, 23 May 2014 22:22:37 +0000 (+0100) Subject: Used a std::atomic for StoreSession::_units_stores and _unit_count X-Git-Tag: pulseview-0.3.0~610 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=b101c41ea084b6dbf5db173759d79f6ca0cb2454;p=pulseview.git Used a std::atomic for StoreSession::_units_stores and _unit_count --- diff --git a/pv/dialogs/storeprogress.cpp b/pv/dialogs/storeprogress.cpp index bbb3881f..ecda1d0e 100644 --- a/pv/dialogs/storeprogress.cpp +++ b/pv/dialogs/storeprogress.cpp @@ -69,17 +69,15 @@ void StoreProgress::on_progress_updated() const std::pair 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 diff --git a/pv/storesession.cpp b/pv/storesession.cpp index fcba344e..a9751343 100644 --- a/pv/storesession.cpp +++ b/pv/storesession.cpp @@ -59,8 +59,7 @@ StoreSession::~StoreSession() pair StoreSession::progress() const { - lock_guard 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 snapshot) const int unit_size = snapshot->unit_size(); assert(unit_size != 0); - { - lock_guard 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 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 snapshot) } start_sample = end_sample; - - { - lock_guard lock(_mutex); - _units_stored = start_sample; - } + _units_stored = start_sample; } + _unit_count = 0; progress_updated(); delete[] data; diff --git a/pv/storesession.h b/pv/storesession.h index 4c9eae01..262eddc1 100644 --- a/pv/storesession.h +++ b/pv/storesession.h @@ -75,9 +75,9 @@ private: std::atomic _interrupt; + std::atomic _units_stored, _unit_count; + mutable std::mutex _mutex; - uint64_t _units_stored; - uint64_t _unit_count; QString _error; };