]> sigrok.org Git - pulseview.git/commitdiff
SigSession: Converted _signals_mutex into a boost::shared_mutex
authorJoel Holdsworth <redacted>
Sun, 5 Oct 2014 17:54:29 +0000 (18:54 +0100)
committerJoel Holdsworth <redacted>
Wed, 19 Nov 2014 10:23:02 +0000 (10:23 +0000)
CMakeLists.txt
pv/popups/channels.cpp
pv/sigsession.cpp
pv/sigsession.h
pv/storesession.cpp
pv/view/decodetrace.cpp
pv/view/view.cpp

index d11f1430d4b9d76cf8e1ef175db8a9f8c26692b6..0ef18566cec4f6db9f63d950683abd0af9a85fc4 100644 (file)
@@ -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.
index 9afc3b48952754047eecce46b3f7aefb2630beb8..ee0daedf4b1035f76c6d6346dc9a59616be8db49 100644 (file)
@@ -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<Channel>, shared_ptr<Signal> > signal_map;
 
-       lock_guard<mutex> lock(_session.signals_mutex());
+       shared_lock<shared_mutex> lock(_session.signals_mutex());
        const vector< shared_ptr<Signal> > &sigs(_session.signals());
 
        for (const shared_ptr<Signal> &sig : sigs)
index 9ff6efe4df6e5d00d00b21a5c41d68f0f4f79acc..11c89e092572e61119a6f96bec53a8e1a30dc775 100644 (file)
 
 #include <libsigrok/libsigrok.hpp>
 
+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<data::SignalData> > SigSession::get_data() const
 {
-       lock_guard<mutex> lock(_signals_mutex);
+       shared_lock<shared_mutex> lock(_signals_mutex);
        set< shared_ptr<data::SignalData> > data;
        for (const shared_ptr<view::Signal> sig : _signals) {
                assert(sig);
@@ -239,7 +243,7 @@ set< shared_ptr<data::SignalData> > 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<mutex> lock(_signals_mutex);
+               lock_guard<boost::shared_mutex> lock(_signals_mutex);
 
                // Create the decoder
                decoder_stack = shared_ptr<data::DecoderStack>(
@@ -308,7 +312,7 @@ bool SigSession::add_decoder(srd_decoder *const dec)
 
 vector< shared_ptr<view::DecodeTrace> > SigSession::get_decode_signals() const
 {
-       lock_guard<mutex> lock(_signals_mutex);
+       shared_lock<shared_mutex> lock(_signals_mutex);
        return _decode_traces;
 }
 
@@ -362,7 +366,7 @@ void SigSession::update_signals(shared_ptr<Device> device)
 
        // Make the Signals list
        {
-               lock_guard<mutex> lock(_signals_mutex);
+               unique_lock<shared_mutex> lock(_signals_mutex);
 
                _signals.clear();
 
@@ -403,7 +407,7 @@ void SigSession::update_signals(shared_ptr<Device> device)
 shared_ptr<view::Signal> SigSession::signal_from_channel(
        shared_ptr<Channel> channel) const
 {
-       lock_guard<mutex> lock(_signals_mutex);
+       lock_guard<boost::shared_mutex> lock(_signals_mutex);
        for (shared_ptr<view::Signal> sig : _signals) {
                assert(sig);
                if (sig->channel() == channel)
index 37ea3abcdcd936f636714d68d2a01915cfee2bda..62994256c80b2008c97158f213a13690ee5af41e 100644 (file)
@@ -29,6 +29,8 @@
 #include <thread>
 #include <vector>
 
+#include <boost/thread.hpp>
+
 #include <QObject>
 #include <QString>
 
@@ -104,7 +106,7 @@ public:
 
        std::set< std::shared_ptr<data::SignalData> > get_data() const;
 
-       std::mutex& signals_mutex() const;
+       boost::shared_mutex& signals_mutex() const;
 
        const std::vector< std::shared_ptr<view::Signal> >& 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<view::Signal> > _signals;
 
        mutable std::mutex _data_mutex;
index 95b8da8738a33f8c808633df283b7190ea6b6d70..ef1c6aad2d245317988066b65c3299033d89ebca 100644 (file)
@@ -29,6 +29,9 @@
 
 #include <libsigrok/libsigrok.hpp>
 
+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::SignalData> > data_set =
                _session.get_data();
 
-       lock_guard<mutex> lock(_session.signals_mutex());
+       shared_lock<shared_mutex> lock(_session.signals_mutex());
        const vector< shared_ptr<view::Signal> > &sigs(_session.signals());
 
        // Check we have logic data
index 138ba0a14263fc92e0ce09cb74232f227d0b0c22..1cb9ce7154a9c302f15e3ecb63637f109f84286a 100644 (file)
@@ -53,6 +53,8 @@ extern "C" {
 #include <pv/widgets/decodergroupbox.h>
 #include <pv/widgets/decodermenu.h>
 
+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<mutex> lock(_session.signals_mutex());
+       shared_lock<shared_mutex> lock(_session.signals_mutex());
        const vector< shared_ptr<Signal> > &sigs(_session.signals());
 
        assert(_decoder_stack);
@@ -731,7 +732,7 @@ void DecodeTrace::commit_decoder_channels(shared_ptr<data::decode::Decoder> &dec
 
        map<const srd_channel*, shared_ptr<LogicSignal> > channel_map;
 
-       lock_guard<mutex> lock(_session.signals_mutex());
+       shared_lock<shared_mutex> lock(_session.signals_mutex());
        const vector< shared_ptr<Signal> > &sigs(_session.signals());
 
        for (const ChannelSelector &s : _channel_selectors)
index 079d8d89b38ffaec8e42b1c6a7f173e56a46bb30..61f017660cab050cc5ae84f0b9d626daef69bcca 100644 (file)
@@ -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<weak_ptr<SelectableItem> > View::selected_items() const
 
 set< shared_ptr<SignalData> > View::get_visible_data() const
 {
-       lock_guard<mutex> lock(session().signals_mutex());
+       shared_lock<shared_mutex> lock(session().signals_mutex());
        const vector< shared_ptr<Signal> > &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<mutex> lock(session().signals_mutex());
+       shared_lock<shared_mutex> lock(session().signals_mutex());
        const vector< shared_ptr<Signal> > &sigs(session().signals());
        for (auto s : sigs)
                add_child_item(s);