From: Joel Holdsworth Date: Sun, 5 Oct 2014 17:54:29 +0000 (+0100) Subject: SigSession: Converted _signals_mutex into a boost::shared_mutex X-Git-Tag: pulseview-0.3.0~471 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=aca64cac30aadeee90510958b081cd385221b258;p=pulseview.git SigSession: Converted _signals_mutex into a boost::shared_mutex --- diff --git a/CMakeLists.txt b/CMakeLists.txt index d11f1430..0ef18566 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,7 +91,7 @@ else() find_package(Qt4 REQUIRED QtCore QtGui QtSvg) endif() -find_package(Boost 1.42 COMPONENTS filesystem system REQUIRED) +find_package(Boost 1.42 COMPONENTS filesystem system thread REQUIRED) # Find the platform's thread library (needed for C++11 threads). # This will set ${CMAKE_THREAD_LIBS_INIT} to the correct, OS-specific value. diff --git a/pv/popups/channels.cpp b/pv/popups/channels.cpp index 9afc3b48..ee0daedf 100644 --- a/pv/popups/channels.cpp +++ b/pv/popups/channels.cpp @@ -35,6 +35,8 @@ using namespace Qt; +using boost::shared_lock; +using boost::shared_mutex; using std::lock_guard; using std::map; using std::mutex; @@ -68,7 +70,7 @@ Channels::Channels(SigSession &session, QWidget *parent) : // Collect a set of signals map, shared_ptr > signal_map; - lock_guard lock(_session.signals_mutex()); + shared_lock lock(_session.signals_mutex()); const vector< shared_ptr > &sigs(_session.signals()); for (const shared_ptr &sig : sigs) diff --git a/pv/sigsession.cpp b/pv/sigsession.cpp index 9ff6efe4..11c89e09 100644 --- a/pv/sigsession.cpp +++ b/pv/sigsession.cpp @@ -47,12 +47,16 @@ #include +using boost::shared_lock; +using boost::shared_mutex; +using boost::unique_lock; + using std::dynamic_pointer_cast; using std::function; using std::lock_guard; -using std::mutex; using std::list; using std::map; +using std::mutex; using std::set; using std::shared_ptr; using std::string; @@ -229,7 +233,7 @@ void SigSession::stop_capture() set< shared_ptr > SigSession::get_data() const { - lock_guard lock(_signals_mutex); + shared_lock lock(_signals_mutex); set< shared_ptr > data; for (const shared_ptr sig : _signals) { assert(sig); @@ -239,7 +243,7 @@ set< shared_ptr > SigSession::get_data() const return data; } -mutex& SigSession::signals_mutex() const +boost::shared_mutex& SigSession::signals_mutex() const { return _signals_mutex; } @@ -257,7 +261,7 @@ bool SigSession::add_decoder(srd_decoder *const dec) try { - lock_guard lock(_signals_mutex); + lock_guard lock(_signals_mutex); // Create the decoder decoder_stack = shared_ptr( @@ -308,7 +312,7 @@ bool SigSession::add_decoder(srd_decoder *const dec) vector< shared_ptr > SigSession::get_decode_signals() const { - lock_guard lock(_signals_mutex); + shared_lock lock(_signals_mutex); return _decode_traces; } @@ -362,7 +366,7 @@ void SigSession::update_signals(shared_ptr device) // Make the Signals list { - lock_guard lock(_signals_mutex); + unique_lock lock(_signals_mutex); _signals.clear(); @@ -403,7 +407,7 @@ void SigSession::update_signals(shared_ptr device) shared_ptr SigSession::signal_from_channel( shared_ptr channel) const { - lock_guard lock(_signals_mutex); + lock_guard lock(_signals_mutex); for (shared_ptr sig : _signals) { assert(sig); if (sig->channel() == channel) diff --git a/pv/sigsession.h b/pv/sigsession.h index 37ea3abc..62994256 100644 --- a/pv/sigsession.h +++ b/pv/sigsession.h @@ -29,6 +29,8 @@ #include #include +#include + #include #include @@ -104,7 +106,7 @@ public: std::set< std::shared_ptr > get_data() const; - std::mutex& signals_mutex() const; + boost::shared_mutex& signals_mutex() const; const std::vector< std::shared_ptr >& signals() const; @@ -159,7 +161,7 @@ private: mutable std::mutex _sampling_mutex; capture_state _capture_state; - mutable std::mutex _signals_mutex; + mutable boost::shared_mutex _signals_mutex; std::vector< std::shared_ptr > _signals; mutable std::mutex _data_mutex; diff --git a/pv/storesession.cpp b/pv/storesession.cpp index 95b8da87..ef1c6aad 100644 --- a/pv/storesession.cpp +++ b/pv/storesession.cpp @@ -29,6 +29,9 @@ #include +using boost::shared_lock; +using boost::shared_mutex; + using std::deque; using std::dynamic_pointer_cast; using std::lock_guard; @@ -80,7 +83,7 @@ bool StoreSession::start() set< shared_ptr > data_set = _session.get_data(); - lock_guard lock(_session.signals_mutex()); + shared_lock lock(_session.signals_mutex()); const vector< shared_ptr > &sigs(_session.signals()); // Check we have logic data diff --git a/pv/view/decodetrace.cpp b/pv/view/decodetrace.cpp index 138ba0a1..1cb9ce71 100644 --- a/pv/view/decodetrace.cpp +++ b/pv/view/decodetrace.cpp @@ -53,6 +53,8 @@ extern "C" { #include #include +using boost::shared_lock; +using boost::shared_mutex; using std::dynamic_pointer_cast; using std::list; using std::lock_guard; @@ -60,7 +62,6 @@ 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; @@ -696,7 +697,7 @@ QComboBox* DecodeTrace::create_channel_selector( { assert(dec); - lock_guard lock(_session.signals_mutex()); + shared_lock lock(_session.signals_mutex()); const vector< shared_ptr > &sigs(_session.signals()); assert(_decoder_stack); @@ -731,7 +732,7 @@ void DecodeTrace::commit_decoder_channels(shared_ptr &dec map > channel_map; - lock_guard lock(_session.signals_mutex()); + shared_lock 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 079d8d89..61f01766 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -43,6 +43,8 @@ #include "pv/data/logic.h" #include "pv/data/logicsnapshot.h" +using boost::shared_lock; +using boost::shared_mutex; using pv::data::SignalData; using std::back_inserter; using std::deque; @@ -51,7 +53,6 @@ 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; @@ -273,7 +274,7 @@ list > View::selected_items() const set< shared_ptr > View::get_visible_data() const { - lock_guard lock(session().signals_mutex()); + shared_lock lock(session().signals_mutex()); const vector< shared_ptr > &sigs(session().signals()); // Make a set of all the visible data objects @@ -522,7 +523,7 @@ void View::signals_changed() // Populate the traces clear_child_items(); - lock_guard lock(session().signals_mutex()); + shared_lock lock(session().signals_mutex()); const vector< shared_ptr > &sigs(session().signals()); for (auto s : sigs) add_child_item(s);