From: Soeren Apel Date: Thu, 5 Mar 2020 20:54:15 +0000 (+0100) Subject: Use shared_ptr for async samples_added() notification X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=720f47623827824dc77dd9dff643c06e570d9068;p=pulseview.git Use shared_ptr for async samples_added() notification --- diff --git a/main.cpp b/main.cpp index 793f4ce1..b0e631f6 100644 --- a/main.cpp +++ b/main.cpp @@ -277,7 +277,7 @@ int main(int argc, char *argv[]) qRegisterMetaType("uint64_t"); qRegisterMetaType("util::Timestamp"); - qRegisterMetaType("data::Segment"); + qRegisterMetaType("SharedPtrToSegment"); // Prepare the global settings since logging needs them early on pv::GlobalSettings settings; diff --git a/pv/data/logic.hpp b/pv/data/logic.hpp index e45ff2f6..b5e532c4 100644 --- a/pv/data/logic.hpp +++ b/pv/data/logic.hpp @@ -21,6 +21,7 @@ #define PULSEVIEW_PV_DATA_LOGIC_HPP #include "signaldata.hpp" +#include "segment.hpp" #include @@ -67,7 +68,7 @@ public: Q_SIGNALS: void samples_cleared(); - void samples_added(shared_ptr segment, uint64_t start_sample, + void samples_added(SharedPtrToSegment segment, uint64_t start_sample, uint64_t end_sample); private: diff --git a/pv/data/logicsegment.cpp b/pv/data/logicsegment.cpp index a1832576..a7df235a 100644 --- a/pv/data/logicsegment.cpp +++ b/pv/data/logicsegment.cpp @@ -341,10 +341,10 @@ void LogicSegment::append_payload(void *data, uint64_t data_size) append_payload_to_mipmap(); if (sample_count > 1) - owner_.notify_samples_added(shared_ptr(shared_from_this()), + owner_.notify_samples_added(SharedPtrToSegment(shared_from_this()), prev_sample_count + 1, prev_sample_count + 1 + sample_count); else - owner_.notify_samples_added(shared_ptr(shared_from_this()), + owner_.notify_samples_added(SharedPtrToSegment(shared_from_this()), prev_sample_count + 1, prev_sample_count + 1); } diff --git a/pv/data/segment.hpp b/pv/data/segment.hpp index 54d236eb..8465949c 100644 --- a/pv/data/segment.hpp +++ b/pv/data/segment.hpp @@ -121,6 +121,8 @@ protected: } // namespace data } // namespace pv -Q_DECLARE_METATYPE(pv::data::Segment); +typedef std::shared_ptr SharedPtrToSegment; + +Q_DECLARE_METATYPE(SharedPtrToSegment); #endif // PULSEVIEW_PV_DATA_SEGMENT_HPP diff --git a/pv/data/signalbase.cpp b/pv/data/signalbase.cpp index 2ca5a835..86ef6856 100644 --- a/pv/data/signalbase.cpp +++ b/pv/data/signalbase.cpp @@ -172,8 +172,8 @@ void SignalBase::set_data(shared_ptr data) if (data_) { connect(data.get(), SIGNAL(samples_cleared()), this, SLOT(on_samples_cleared())); - connect(data.get(), SIGNAL(samples_added(shared_ptr, uint64_t, uint64_t)), - this, SLOT(on_samples_added(shared_ptr, uint64_t, uint64_t))); + connect(data.get(), SIGNAL(samples_added(SharedPtrToSegment, uint64_t, uint64_t)), + this, SLOT(on_samples_added(SharedPtrToSegment, uint64_t, uint64_t))); if (channel_type_ == AnalogChannel) { shared_ptr analog = analog_data(); @@ -752,7 +752,7 @@ void SignalBase::on_samples_cleared() samples_cleared(); } -void SignalBase::on_samples_added(shared_ptr segment, uint64_t start_sample, +void SignalBase::on_samples_added(SharedPtrToSegment segment, uint64_t start_sample, uint64_t end_sample) { if (conversion_type_ != NoConversion) { diff --git a/pv/data/signalbase.hpp b/pv/data/signalbase.hpp index 733900d5..065dbc99 100644 --- a/pv/data/signalbase.hpp +++ b/pv/data/signalbase.hpp @@ -35,6 +35,8 @@ #include +#include "segment.hpp" + using std::atomic; using std::condition_variable; using std::map; @@ -323,7 +325,7 @@ Q_SIGNALS: private Q_SLOTS: void on_samples_cleared(); - void on_samples_added(shared_ptr segment, uint64_t start_sample, + void on_samples_added(SharedPtrToSegment segment, uint64_t start_sample, uint64_t end_sample); void on_min_max_changed(float min, float max);