From: Joel Holdsworth Date: Sun, 5 Oct 2014 10:09:51 +0000 (+0100) Subject: SigSession: Added signals_mutex(), and made signals() give a reference X-Git-Tag: pulseview-0.3.0~472 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=c3a740dd5d095eb1cdf42e00df4d5a5c480ac5b3;p=pulseview.git SigSession: Added signals_mutex(), and made signals() give a reference --- diff --git a/pv/popups/channels.cpp b/pv/popups/channels.cpp index f6b5aa14..9afc3b48 100644 --- a/pv/popups/channels.cpp +++ b/pv/popups/channels.cpp @@ -35,7 +35,9 @@ using namespace Qt; +using std::lock_guard; using std::map; +using std::mutex; using std::set; using std::shared_ptr; using std::vector; @@ -65,7 +67,9 @@ Channels::Channels(SigSession &session, QWidget *parent) : // Collect a set of signals map, shared_ptr > signal_map; - const vector< shared_ptr > sigs = _session.get_signals(); + + lock_guard lock(_session.signals_mutex()); + const vector< shared_ptr > &sigs(_session.signals()); for (const shared_ptr &sig : sigs) signal_map[sig->channel()] = sig; diff --git a/pv/sigsession.cpp b/pv/sigsession.cpp index d1f3a606..9ff6efe4 100644 --- a/pv/sigsession.cpp +++ b/pv/sigsession.cpp @@ -239,9 +239,13 @@ set< shared_ptr > SigSession::get_data() const return data; } -vector< shared_ptr > SigSession::get_signals() const +mutex& SigSession::signals_mutex() const +{ + return _signals_mutex; +} + +const vector< shared_ptr >& SigSession::signals() const { - lock_guard lock(_signals_mutex); return _signals; } diff --git a/pv/sigsession.h b/pv/sigsession.h index 08a0fd0f..37ea3abc 100644 --- a/pv/sigsession.h +++ b/pv/sigsession.h @@ -104,8 +104,9 @@ public: std::set< std::shared_ptr > get_data() const; - std::vector< std::shared_ptr > - get_signals() const; + std::mutex& signals_mutex() const; + + const std::vector< std::shared_ptr >& signals() const; #ifdef ENABLE_DECODE bool add_decoder(srd_decoder *const dec); diff --git a/pv/storesession.cpp b/pv/storesession.cpp index 4de9d56d..95b8da87 100644 --- a/pv/storesession.cpp +++ b/pv/storesession.cpp @@ -79,8 +79,9 @@ bool StoreSession::start() { set< shared_ptr > data_set = _session.get_data(); - const vector< shared_ptr > sigs = - _session.get_signals(); + + lock_guard lock(_session.signals_mutex()); + const vector< shared_ptr > &sigs(_session.signals()); // Check we have logic data if (data_set.empty() || sigs.empty()) { diff --git a/pv/view/decodetrace.cpp b/pv/view/decodetrace.cpp index 899de3b2..138ba0a1 100644 --- a/pv/view/decodetrace.cpp +++ b/pv/view/decodetrace.cpp @@ -22,6 +22,8 @@ extern "C" { #include } +#include + #include #include @@ -53,10 +55,12 @@ extern "C" { using std::dynamic_pointer_cast; using std::list; +using std::lock_guard; using std::make_pair; using std::max; using std::map; using std::min; +using std::mutex; using std::pair; using std::shared_ptr; using std::tie; @@ -692,7 +696,8 @@ QComboBox* DecodeTrace::create_channel_selector( { assert(dec); - const vector< shared_ptr > sigs = _session.get_signals(); + lock_guard lock(_session.signals_mutex()); + const vector< shared_ptr > &sigs(_session.signals()); assert(_decoder_stack); const auto channel_iter = dec->channels().find(pdch); @@ -725,7 +730,9 @@ void DecodeTrace::commit_decoder_channels(shared_ptr &dec assert(dec); map > channel_map; - const vector< shared_ptr > sigs = _session.get_signals(); + + lock_guard lock(_session.signals_mutex()); + const vector< shared_ptr > &sigs(_session.signals()); for (const ChannelSelector &s : _channel_selectors) { diff --git a/pv/view/view.cpp b/pv/view/view.cpp index fae74f8f..079d8d89 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -22,9 +22,10 @@ #include #endif -#include -#include -#include +#include +#include +#include +#include #include #include @@ -46,9 +47,11 @@ using pv::data::SignalData; using std::back_inserter; using std::deque; using std::list; +using std::lock_guard; using std::max; using std::make_pair; using std::min; +using std::mutex; using std::pair; using std::set; using std::shared_ptr; @@ -214,9 +217,6 @@ void View::zoom_one_to_one() { using pv::data::SignalData; - const vector< shared_ptr > sigs( - session().get_signals()); - // Make a set of all the visible data objects set< shared_ptr > visible_data = get_visible_data(); if (visible_data.empty()) @@ -273,8 +273,8 @@ list > View::selected_items() const set< shared_ptr > View::get_visible_data() const { - const vector< shared_ptr > sigs( - session().get_signals()); + lock_guard lock(session().signals_mutex()); + const vector< shared_ptr > &sigs(session().signals()); // Make a set of all the visible data objects set< shared_ptr > visible_data; @@ -522,8 +522,8 @@ void View::signals_changed() // Populate the traces clear_child_items(); - const vector< shared_ptr > sigs( - session().get_signals()); + lock_guard lock(session().signals_mutex()); + const vector< shared_ptr > &sigs(session().signals()); for (auto s : sigs) add_child_item(s);