From: Soeren Apel Date: Tue, 18 Aug 2020 11:35:31 +0000 (+0200) Subject: SignalBase: Prevent race condition for memory access X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=eb8f22c04d1f5b7f9c831f9bec0778d3f3583626;p=pulseview.git SignalBase: Prevent race condition for memory access --- diff --git a/pv/data/signalbase.cpp b/pv/data/signalbase.cpp index c15a4431..274de1a1 100644 --- a/pv/data/signalbase.cpp +++ b/pv/data/signalbase.cpp @@ -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 asegment, + shared_ptr 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 asegment, + shared_ptr 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 asegment = analog_data->analog_segments().front(); assert(asegment); const shared_ptr logic_data = dynamic_pointer_cast(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 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_) { diff --git a/pv/data/signalbase.hpp b/pv/data/signalbase.hpp index ab1c97a0..89bfc252 100644 --- a/pv/data/signalbase.hpp +++ b/pv/data/signalbase.hpp @@ -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 asegment, + shared_ptr lsegment, uint64_t start_sample, uint64_t end_sample); + void convert_single_segment(shared_ptr asegment, + shared_ptr lsegment); void conversion_thread_proc(); void stop_conversion();