SignalBase: Prevent race condition for memory access
authorSoeren Apel <soeren@apelpie.net>
Tue, 18 Aug 2020 11:35:31 +0000 (13:35 +0200)
committerSoeren Apel <soeren@apelpie.net>
Sat, 22 Aug 2020 22:16:19 +0000 (00:16 +0200)
pv/data/signalbase.cpp
pv/data/signalbase.hpp

index c15a44319d21030b3795fcdd3e25b8513869ce49..274de1a12667350a2acb1ad5ca7f2959958610b3 100644 (file)
@@ -601,8 +601,8 @@ bool SignalBase::conversion_is_a2l() const
                (conversion_type_ == A2LConversionBySchmittTrigger)));
 }
 
-void SignalBase::convert_single_segment_range(AnalogSegment *asegment,
-       LogicSegment *lsegment, uint64_t start_sample, uint64_t end_sample)
+void SignalBase::convert_single_segment_range(shared_ptr<AnalogSegment> asegment,
+       shared_ptr<LogicSegment> lsegment, uint64_t start_sample, uint64_t end_sample)
 {
        if (end_sample > start_sample) {
                tie(min_value_, max_value_) = asegment->get_min_max();
@@ -701,7 +701,8 @@ void SignalBase::convert_single_segment_range(AnalogSegment *asegment,
        }
 }
 
-void SignalBase::convert_single_segment(AnalogSegment *asegment, LogicSegment *lsegment)
+void SignalBase::convert_single_segment(shared_ptr<AnalogSegment> asegment,
+       shared_ptr<LogicSegment> lsegment)
 {
        uint64_t start_sample, end_sample, old_end_sample;
        start_sample = end_sample = 0;
@@ -755,7 +756,7 @@ void SignalBase::conversion_thread_proc()
 
        uint32_t segment_id = 0;
 
-       AnalogSegment *asegment = analog_data->analog_segments().front().get();
+       shared_ptr<AnalogSegment> asegment = analog_data->analog_segments().front();
        assert(asegment);
 
        const shared_ptr<Logic> logic_data = dynamic_pointer_cast<Logic>(converted_data_);
@@ -768,7 +769,7 @@ void SignalBase::conversion_thread_proc()
                logic_data->push_segment(new_segment);
        }
 
-       LogicSegment *lsegment = logic_data->logic_segments().front().get();
+       shared_ptr<LogicSegment> lsegment = logic_data->logic_segments().front();
        assert(lsegment);
 
        do {
@@ -781,7 +782,7 @@ void SignalBase::conversion_thread_proc()
                        segment_id++;
 
                        try {
-                               asegment = analog_data->analog_segments().at(segment_id).get();
+                               asegment = analog_data->analog_segments().at(segment_id);
                        } catch (out_of_range&) {
                                qDebug() << "Conversion error for" << name() << ": no analog segment" \
                                        << segment_id << ", segments size is" << analog_data->analog_segments().size();
@@ -792,7 +793,7 @@ void SignalBase::conversion_thread_proc()
                                *logic_data.get(), segment_id, 1, asegment->samplerate());
                        logic_data->push_segment(new_segment);
 
-                       lsegment = logic_data->logic_segments().back().get();
+                       lsegment = logic_data->logic_segments().back();
                } else {
                        // No more samples/segments to process, wait for data or interrupt
                        if (!conversion_interrupt_) {
index ab1c97a0530ddc55b6a8e5005e9582ec022f0768..89bfc25298369bf1431e3fa05f325bba1abd0e74 100644 (file)
@@ -353,10 +353,10 @@ private:
        uint8_t convert_a2l_schmitt_trigger(float lo_thr, float hi_thr,
                float value, uint8_t &state);
 
-       void convert_single_segment_range(AnalogSegment *asegment,
-               LogicSegment *lsegment, uint64_t start_sample, uint64_t end_sample);
-       void convert_single_segment(pv::data::AnalogSegment *asegment,
-               pv::data::LogicSegment *lsegment);
+       void convert_single_segment_range(shared_ptr<AnalogSegment> asegment,
+               shared_ptr<LogicSegment> lsegment, uint64_t start_sample, uint64_t end_sample);
+       void convert_single_segment(shared_ptr<AnalogSegment> asegment,
+               shared_ptr<LogicSegment> lsegment);
        void conversion_thread_proc();
 
        void stop_conversion();