From: Joel Holdsworth Date: Sun, 2 Dec 2012 15:21:03 +0000 (+0000) Subject: Mutex protected SigSession::_signals X-Git-Tag: pulseview-0.1.0~206 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=3868e5fa3081573891ff2ae5b9dd67eb4a6afa4b;p=pulseview.git Mutex protected SigSession::_signals --- diff --git a/pv/sigsession.cpp b/pv/sigsession.cpp index e8585c5f..63a683df 100644 --- a/pv/sigsession.cpp +++ b/pv/sigsession.cpp @@ -75,8 +75,9 @@ void SigSession::start_capture(struct sr_dev_inst *sdi, record_length, sample_rate)); } -vector< shared_ptr >& SigSession::get_signals() +vector< shared_ptr > SigSession::get_signals() { + lock_guard 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 lock(_data_mutex); + lock_guard 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 lock(_data_mutex); - const sr_datafeed_meta_logic &meta_logic = *(sr_datafeed_meta_logic*)packet->payload; + { + lock_guard 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 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: { diff --git a/pv/sigsession.h b/pv/sigsession.h index 763fc169..307330ec 100644 --- a/pv/sigsession.h +++ b/pv/sigsession.h @@ -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 >& + std::vector< boost::shared_ptr > get_signals(); boost::shared_ptr 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 > _signals; + + mutable boost::mutex _data_mutex; boost::shared_ptr _logic_data; boost::shared_ptr _cur_logic_snapshot; diff --git a/pv/view/header.cpp b/pv/view/header.cpp index 744e4aff..5f1de744 100644 --- a/pv/view/header.cpp +++ b/pv/view/header.cpp @@ -63,8 +63,8 @@ boost::shared_ptr Header::get_mouse_over_signal( const QPoint &pt) { const int w = width(); - const vector< shared_ptr > &sigs = - _view.session().get_signals(); + const vector< shared_ptr > sigs( + _view.session().get_signals()); const int v_offset = _view.v_offset(); BOOST_FOREACH(const shared_ptr s, sigs) @@ -85,8 +85,8 @@ boost::shared_ptr Header::get_mouse_over_signal( void Header::paintEvent(QPaintEvent *event) { const int w = width(); - const vector< shared_ptr > &sigs = - _view.session().get_signals(); + const vector< shared_ptr > 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 > &sigs = - _view.session().get_signals(); + const vector< shared_ptr > sigs( + _view.session().get_signals()); if(event->button() & Qt::LeftButton) { _mouse_down_point = event->pos(); diff --git a/pv/view/view.cpp b/pv/view/view.cpp index 7a444f7c..e0fce889 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -173,7 +173,7 @@ const QPoint& View::hover_point() const void View::normalize_layout() { - vector< shared_ptr > &sigs = _session.get_signals(); + const vector< shared_ptr > sigs(_session.get_signals()); int v_min = INT_MAX; BOOST_FOREACH(const shared_ptr s, sigs) @@ -229,7 +229,7 @@ void View::update_scroll() void View::reset_signal_layout() { int offset = SignalMargin; - vector< shared_ptr > &sigs = _session.get_signals(); + const vector< shared_ptr > sigs(_session.get_signals()); BOOST_FOREACH(shared_ptr s, sigs) { s->set_v_offset(offset); offset += SignalHeight + 2 * SignalMargin; diff --git a/pv/view/viewport.cpp b/pv/view/viewport.cpp index 96111875..03b07fdf 100644 --- a/pv/view/viewport.cpp +++ b/pv/view/viewport.cpp @@ -49,8 +49,9 @@ Viewport::Viewport(View &parent) : int Viewport::get_total_height() const { int h = 0; - BOOST_FOREACH(const shared_ptr s, - _view.session().get_signals()) { + const vector< shared_ptr > sigs( + _view.session().get_signals()); + BOOST_FOREACH(const shared_ptr 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 > &sigs = - _view.session().get_signals(); + const vector< shared_ptr > sigs( + _view.session().get_signals()); QPainter p(this); p.setRenderHint(QPainter::Antialiasing);