]> sigrok.org Git - pulseview.git/commitdiff
SigSession: Added signals_mutex(), and made signals() give a reference
authorJoel Holdsworth <redacted>
Sun, 5 Oct 2014 10:09:51 +0000 (11:09 +0100)
committerJoel Holdsworth <redacted>
Wed, 19 Nov 2014 10:23:02 +0000 (10:23 +0000)
pv/popups/channels.cpp
pv/sigsession.cpp
pv/sigsession.h
pv/storesession.cpp
pv/view/decodetrace.cpp
pv/view/view.cpp

index f6b5aa14e99317cb6d08e35f70d265e4ea5a6927..9afc3b48952754047eecce46b3f7aefb2630beb8 100644 (file)
@@ -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<Channel>, shared_ptr<Signal> > signal_map;
-       const vector< shared_ptr<Signal> > sigs = _session.get_signals();
+
+       lock_guard<mutex> lock(_session.signals_mutex());
+       const vector< shared_ptr<Signal> > &sigs(_session.signals());
 
        for (const shared_ptr<Signal> &sig : sigs)
                signal_map[sig->channel()] = sig;
index d1f3a6062cde8b02f881bd9ffa33972edd39b5ef..9ff6efe4df6e5d00d00b21a5c41d68f0f4f79acc 100644 (file)
@@ -239,9 +239,13 @@ set< shared_ptr<data::SignalData> > SigSession::get_data() const
        return data;
 }
 
-vector< shared_ptr<view::Signal> > SigSession::get_signals() const
+mutex& SigSession::signals_mutex() const
+{
+       return _signals_mutex;
+}
+
+const vector< shared_ptr<view::Signal> >& SigSession::signals() const
 {
-       lock_guard<mutex> lock(_signals_mutex);
        return _signals;
 }
 
index 08a0fd0fadb5cbe23b89e8e93acea84dae027599..37ea3abcdcd936f636714d68d2a01915cfee2bda 100644 (file)
@@ -104,8 +104,9 @@ public:
 
        std::set< std::shared_ptr<data::SignalData> > get_data() const;
 
-       std::vector< std::shared_ptr<view::Signal> >
-               get_signals() const;
+       std::mutex& signals_mutex() const;
+
+       const std::vector< std::shared_ptr<view::Signal> >& signals() const;
 
 #ifdef ENABLE_DECODE
        bool add_decoder(srd_decoder *const dec);
index 4de9d56dde2cc676899404a27040ab6ec88f0967..95b8da8738a33f8c808633df283b7190ea6b6d70 100644 (file)
@@ -79,8 +79,9 @@ bool StoreSession::start()
 {
        set< shared_ptr<data::SignalData> > data_set =
                _session.get_data();
-       const vector< shared_ptr<view::Signal> > sigs =
-               _session.get_signals();
+
+       lock_guard<mutex> lock(_session.signals_mutex());
+       const vector< shared_ptr<view::Signal> > &sigs(_session.signals());
 
        // Check we have logic data
        if (data_set.empty() || sigs.empty()) {
index 899de3b238743f320d638c87308719f9f961ddc7..138ba0a14263fc92e0ce09cb74232f227d0b0c22 100644 (file)
@@ -22,6 +22,8 @@ extern "C" {
 #include <libsigrokdecode/libsigrokdecode.h>
 }
 
+#include <mutex>
+
 #include <extdef.h>
 
 #include <tuple>
@@ -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<Signal> > sigs = _session.get_signals();
+       lock_guard<mutex> lock(_session.signals_mutex());
+       const vector< shared_ptr<Signal> > &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<data::decode::Decoder> &dec
        assert(dec);
 
        map<const srd_channel*, shared_ptr<LogicSignal> > channel_map;
-       const vector< shared_ptr<Signal> > sigs = _session.get_signals();
+
+       lock_guard<mutex> lock(_session.signals_mutex());
+       const vector< shared_ptr<Signal> > &sigs(_session.signals());
 
        for (const ChannelSelector &s : _channel_selectors)
        {
index fae74f8f5739600ab8ffedd5aee153b313d5e44b..079d8d89b38ffaec8e42b1c6a7f173e56a46bb30 100644 (file)
 #include <libsigrokdecode/libsigrokdecode.h>
 #endif
 
-#include <assert.h>
-#include <limits.h>
-#include <math.h>
+#include <cassert>
+#include <climits>
+#include <cmath>
+#include <mutex>
 
 #include <QEvent>
 #include <QMouseEvent>
@@ -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<Signal> > sigs(
-               session().get_signals());
-
        // Make a set of all the visible data objects
        set< shared_ptr<SignalData> > visible_data = get_visible_data();
        if (visible_data.empty())
@@ -273,8 +273,8 @@ list<weak_ptr<SelectableItem> > View::selected_items() const
 
 set< shared_ptr<SignalData> > View::get_visible_data() const
 {
-       const vector< shared_ptr<Signal> > sigs(
-               session().get_signals());
+       lock_guard<mutex> lock(session().signals_mutex());
+       const vector< shared_ptr<Signal> > &sigs(session().signals());
 
        // Make a set of all the visible data objects
        set< shared_ptr<SignalData> > visible_data;
@@ -522,8 +522,8 @@ void View::signals_changed()
        // Populate the traces
        clear_child_items();
 
-       const vector< shared_ptr<Signal> > sigs(
-               session().get_signals());
+       lock_guard<mutex> lock(session().signals_mutex());
+       const vector< shared_ptr<Signal> > &sigs(session().signals());
        for (auto s : sigs)
                add_child_item(s);