]> sigrok.org Git - pulseview.git/commitdiff
Mutex protected SigSession::_signals
authorJoel Holdsworth <redacted>
Sun, 2 Dec 2012 15:21:03 +0000 (15:21 +0000)
committerJoel Holdsworth <redacted>
Tue, 11 Dec 2012 20:05:19 +0000 (20:05 +0000)
pv/sigsession.cpp
pv/sigsession.h
pv/view/header.cpp
pv/view/view.cpp
pv/view/viewport.cpp

index e8585c5f84db1465a8a482cbe6266eabc60e270f..63a683df8eb7a5310907b95154891728a42481f4 100644 (file)
@@ -75,8 +75,9 @@ void SigSession::start_capture(struct sr_dev_inst *sdi,
                record_length, sample_rate));
 }
 
-vector< shared_ptr<view::Signal> >& SigSession::get_signals()
+vector< shared_ptr<view::Signal> > SigSession::get_signals()
 {
+       lock_guard<mutex> lock(_signals_mutex);
        return _signals;
 }
 
@@ -131,7 +132,7 @@ void SigSession::data_feed_in(const struct sr_dev_inst *sdi,
        switch (packet->type) {
        case SR_DF_HEADER:
        {
-               lock_guard<mutex> lock(_data_mutex);
+               lock_guard<mutex> lock(_signals_mutex);
                _signals.clear();
                break;
        }
@@ -139,17 +140,21 @@ void SigSession::data_feed_in(const struct sr_dev_inst *sdi,
        case SR_DF_META_LOGIC:
        {
                assert(packet->payload);
-
-               lock_guard<mutex> lock(_data_mutex);
-
                const sr_datafeed_meta_logic &meta_logic =
                        *(sr_datafeed_meta_logic*)packet->payload;
 
+       {
+               lock_guard<mutex> lock(_data_mutex);
+
                // Create an empty LogiData for coming data snapshots
                _logic_data.reset(new LogicData(meta_logic));
                assert(_logic_data);
                if(!_logic_data)
                        break;
+       }
+
+       {
+               lock_guard<mutex> lock(_signals_mutex);
 
                // Add the signals
                for (int i = 0; i < meta_logic.num_probes; i++)
@@ -170,6 +175,7 @@ void SigSession::data_feed_in(const struct sr_dev_inst *sdi,
                signals_changed();
                break;
        }
+       }
 
        case SR_DF_LOGIC:
        {
index 763fc16903cc17372e07f5c08cb63d897b41b91f..307330ecb3e40065cc26b5dd8a05b6617b71ace3 100644 (file)
@@ -57,7 +57,7 @@ public:
        void start_capture(struct sr_dev_inst* sdi, uint64_t record_length,
                uint64_t sample_rate);
 
-       std::vector< boost::shared_ptr<view::Signal> >&
+       std::vector< boost::shared_ptr<view::Signal> >
                get_signals();
 
        boost::shared_ptr<LogicData> get_data();
@@ -73,8 +73,10 @@ private:
                struct sr_datafeed_packet *packet);
 
 private:
-       mutable boost::mutex _data_mutex;
+       mutable boost::mutex _signals_mutex;
        std::vector< boost::shared_ptr<view::Signal> > _signals;
+
+       mutable boost::mutex _data_mutex;
        boost::shared_ptr<LogicData> _logic_data;
        boost::shared_ptr<LogicDataSnapshot> _cur_logic_snapshot;
 
index 744e4aff06b2072006c68fe4880b973f195e05d7..5f1de744a1d7e5642d6f364f66672f1020aa7a12 100644 (file)
@@ -63,8 +63,8 @@ boost::shared_ptr<pv::view::Signal> Header::get_mouse_over_signal(
        const QPoint &pt)
 {
        const int w = width();
-       const vector< shared_ptr<Signal> > &sigs =
-               _view.session().get_signals();
+       const vector< shared_ptr<Signal> > sigs(
+               _view.session().get_signals());
 
        const int v_offset = _view.v_offset();
        BOOST_FOREACH(const shared_ptr<Signal> s, sigs)
@@ -85,8 +85,8 @@ boost::shared_ptr<pv::view::Signal> Header::get_mouse_over_signal(
 void Header::paintEvent(QPaintEvent *event)
 {
        const int w = width();
-       const vector< shared_ptr<Signal> > &sigs =
-               _view.session().get_signals();
+       const vector< shared_ptr<Signal> > sigs(
+               _view.session().get_signals());
 
        QPainter painter(this);
        painter.setRenderHint(QPainter::Antialiasing);
@@ -113,8 +113,8 @@ void Header::mousePressEvent(QMouseEvent *event)
 {
        assert(event);
 
-       const vector< shared_ptr<Signal> > &sigs =
-               _view.session().get_signals();
+       const vector< shared_ptr<Signal> > sigs(
+               _view.session().get_signals());
 
        if(event->button() & Qt::LeftButton) {
                _mouse_down_point = event->pos();
index 7a444f7c47f68b1032e6a0b359366afb4272e50f..e0fce889fe06431c6122c4eaad1ec2a9938b6d39 100644 (file)
@@ -173,7 +173,7 @@ const QPoint& View::hover_point() const
 
 void View::normalize_layout()
 {
-       vector< shared_ptr<Signal> > &sigs = _session.get_signals();
+       const vector< shared_ptr<Signal> > sigs(_session.get_signals());
 
        int v_min = INT_MAX;
        BOOST_FOREACH(const shared_ptr<Signal> s, sigs)
@@ -229,7 +229,7 @@ void View::update_scroll()
 void View::reset_signal_layout()
 {
        int offset = SignalMargin;
-       vector< shared_ptr<Signal> > &sigs = _session.get_signals();
+       const vector< shared_ptr<Signal> > sigs(_session.get_signals());
        BOOST_FOREACH(shared_ptr<Signal> s, sigs) {
                s->set_v_offset(offset);
                offset += SignalHeight + 2 * SignalMargin;
index 96111875570ee7e53bf0e9773285686acb01e8a8..03b07fdf13351d3ceab1e8720af701f503046335 100644 (file)
@@ -49,8 +49,9 @@ Viewport::Viewport(View &parent) :
 int Viewport::get_total_height() const
 {
        int h = 0;
-       BOOST_FOREACH(const shared_ptr<Signal> s,
-               _view.session().get_signals()) {
+       const vector< shared_ptr<Signal> > sigs(
+               _view.session().get_signals());
+       BOOST_FOREACH(const shared_ptr<Signal> s, sigs) {
                assert(s);
                h = max(s->get_v_offset() + View::SignalHeight, h);
        }
@@ -60,8 +61,8 @@ int Viewport::get_total_height() const
 
 void Viewport::paintEvent(QPaintEvent *event)
 {
-       const vector< shared_ptr<Signal> > &sigs =
-               _view.session().get_signals();
+       const vector< shared_ptr<Signal> > sigs(
+               _view.session().get_signals());
 
        QPainter p(this);
        p.setRenderHint(QPainter::Antialiasing);