From: Soeren Apel Date: Thu, 19 May 2016 18:29:37 +0000 (+0200) Subject: Session: Keep track of signal data locally X-Git-Tag: pulseview-0.4.0~295 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=cc9a7898ee7afc32e03dbcc991ed7ba722ed8f1b;p=pulseview.git Session: Keep track of signal data locally Currently, the Session class doesn't hold pointers to the signal data itself but instead fetches the data on demand using the list of signals it has. As the Session is providing the model in the MVC paradigm, it owns the data and thus should keep track of it directly. The signals are (in an ideal world) mere views on that data, so querying them for the signal data isn't good style. --- diff --git a/pv/session.cpp b/pv/session.cpp index 4bc510e9..6b7645bc 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -140,8 +140,14 @@ void Session::set_device(shared_ptr device) device_.reset(); - // Remove all traces + // Remove all stored data signals_.clear(); + { + shared_lock lock(signals_mutex_); + for (const shared_ptr d : all_signal_data_) + d->clear(); + } + all_signal_data_.clear(); cur_logic_segment_.reset(); for (auto entry : cur_analog_segments_) { @@ -205,8 +211,11 @@ void Session::start_capture(function error_handler) } // Clear signal data - for (const shared_ptr d : get_data()) - d->clear(); + { + shared_lock lock(signals_mutex_); + for (const shared_ptr d : all_signal_data_) + d->clear(); + } // Begin the session sampling_thread_ = std::thread( @@ -224,30 +233,20 @@ void Session::stop_capture() sampling_thread_.join(); } -set< shared_ptr > Session::get_data() const -{ - shared_lock lock(signals_mutex_); - set< shared_ptr > data; - for (const shared_ptr sig : signals_) { - assert(sig); - data.insert(sig->data()); - } - - return data; -} - double Session::get_samplerate() const { double samplerate = 0.0; - for (const shared_ptr d : get_data()) { - assert(d); - const vector< shared_ptr > segments = - d->segments(); - for (const shared_ptr &s : segments) - samplerate = std::max(samplerate, s->samplerate()); + { + shared_lock lock(signals_mutex_); + for (const shared_ptr d : all_signal_data_) { + assert(d); + const vector< shared_ptr > segments = + d->segments(); + for (const shared_ptr &s : segments) + samplerate = std::max(samplerate, s->samplerate()); + } } - // If there is no sample rate given we use samples as unit if (samplerate == 0.0) samplerate = 1.0; @@ -415,6 +414,7 @@ void Session::update_signals() new view::LogicSignal(*this, device_, channel, logic_data_)); + all_signal_data_.insert(logic_data_); break; case SR_CHANNEL_ANALOG: @@ -424,6 +424,7 @@ void Session::update_signals() signal = shared_ptr( new view::AnalogSignal( *this, channel, data)); + all_signal_data_.insert(data); break; } @@ -519,17 +520,20 @@ void Session::feed_in_trigger() // The channel containing most samples should be most accurate uint64_t sample_count = 0; - for (const shared_ptr d : get_data()) { - assert(d); - uint64_t temp_count = 0; - - const vector< shared_ptr > segments = - d->segments(); - for (const shared_ptr &s : segments) - temp_count += s->get_sample_count(); - - if (temp_count > sample_count) - sample_count = temp_count; + { + shared_lock lock(signals_mutex_); + for (const shared_ptr d : all_signal_data_) { + assert(d); + uint64_t temp_count = 0; + + const vector< shared_ptr > segments = + d->segments(); + for (const shared_ptr &s : segments) + temp_count += s->get_sample_count(); + + if (temp_count > sample_count) + sample_count = temp_count; + } } trigger_event(sample_count / get_samplerate()); diff --git a/pv/session.hpp b/pv/session.hpp index ac3d654c..22705c36 100644 --- a/pv/session.hpp +++ b/pv/session.hpp @@ -114,8 +114,6 @@ public: void stop_capture(); - std::set< std::shared_ptr > get_data() const; - double get_samplerate() const; const std::unordered_set< std::shared_ptr > @@ -168,6 +166,7 @@ private: mutable boost::shared_mutex signals_mutex_; std::unordered_set< std::shared_ptr > signals_; + std::set< std::shared_ptr > all_signal_data_; mutable std::recursive_mutex data_mutex_; std::shared_ptr logic_data_;