Passing segment instances fails because this creates a race condition.
When a long conversion is taking place, the SignalBase::samples_added
signal is called often but since it's in a separate thread, the calls
are queued and aren't executed immediately. Now if the conversion is
restarted - for example as a result of a changed conversion threshold -
then the segments holding the converted data are destroyed, rendering
the pointers submitted as parameters to samples_added invalid.
Once the signal queue is processed, those invalid pointers will be
accessed and PV segfaults.
Since the signal queue can neither be emptied nor flushed, this
leaves only two sensible choices:
1) Signal samples_added less often, thereby reducing the chance of
signals being queued
2) Supply the segment ID instead of the segment instance as that's
essentially the only thing we currently care about - in fact, the
only user of samples_added (ViewBase::on_samples_added) uses the
instance to query only this
As #1 is only a band-aid and not a waterproof solution, I chose
to go with #2.
analog->get_logic_via_threshold(threshold, lsamples);
lsegment->append_payload(logic->data_pointer(), logic->data_length());
-
- samples_added(lsegment, i, i + ConversionBlockSize);
+ samples_added(lsegment->segment_id(), i, i + ConversionBlockSize);
i += ConversionBlockSize;
}
shared_ptr<sigrok::Logic> logic =
analog->get_logic_via_threshold(threshold, lsamples);
lsegment->append_payload(logic->data_pointer(), logic->data_length());
- samples_added(lsegment, i, end_sample);
+ samples_added(lsegment->segment_id(), i, end_sample);
}
if (conversion_type_ == A2LConversionBySchmittTrigger) {
&state, lsamples);
lsegment->append_payload(logic->data_pointer(), logic->data_length());
-
- samples_added(lsegment, i, i + ConversionBlockSize);
+ samples_added(lsegment->segment_id(), i, i + ConversionBlockSize);
i += ConversionBlockSize;
}
analog->get_logic_via_schmitt_trigger(lo_thr, hi_thr,
&state, lsamples);
lsegment->append_payload(logic->data_pointer(), logic->data_length());
- samples_added(lsegment, i, end_sample);
+ samples_added(lsegment->segment_id(), i, end_sample);
}
// If acquisition is ongoing, start-/endsample may have changed
}
}
- samples_added(segment, start_sample, end_sample);
+ data::Segment* s = qobject_cast<data::Segment*>(segment);
+ samples_added(s->segment_id(), start_sample, end_sample);
}
void SignalBase::on_min_max_changed(float min, float max)
void samples_cleared();
- void samples_added(QObject* segment, uint64_t start_sample,
+ void samples_added(uint64_t segment_id, uint64_t start_sample,
uint64_t end_sample);
void min_max_changed(float min, float max);
for (shared_ptr<data::SignalBase> signalbase : signalbases_) {
disconnect(signalbase.get(), SIGNAL(samples_cleared()),
this, SLOT(on_data_updated()));
- disconnect(signalbase.get(), SIGNAL(samples_added(QObject*, uint64_t, uint64_t)),
- this, SLOT(on_samples_added(QObject*, uint64_t, uint64_t)));
+ disconnect(signalbase.get(), SIGNAL(samples_added(uint64_t, uint64_t, uint64_t)),
+ this, SLOT(on_samples_added(uint64_t, uint64_t, uint64_t)));
}
signalbases_.clear();
connect(signalbase.get(), SIGNAL(samples_cleared()),
this, SLOT(on_data_updated()));
- connect(signalbase.get(), SIGNAL(samples_added(QObject*, uint64_t, uint64_t)),
- this, SLOT(on_samples_added(QObject*, uint64_t, uint64_t)));
+ connect(signalbase.get(), SIGNAL(samples_added(uint64_t, uint64_t, uint64_t)),
+ this, SLOT(on_samples_added(uint64_t, uint64_t, uint64_t)));
}
#ifdef ENABLE_DECODE
{
}
-void ViewBase::on_samples_added(QObject* segment, uint64_t start_sample,
+void ViewBase::on_samples_added(uint64_t segment_id, uint64_t start_sample,
uint64_t end_sample)
{
(void)start_sample;
(void)end_sample;
- data::Segment* s = qobject_cast<data::Segment*>(segment);
-
- if (s->segment_id() != current_segment_)
+ if (segment_id != current_segment_)
return;
if (!delayed_view_updater_.isActive())
virtual void perform_delayed_view_update();
private Q_SLOTS:
- void on_samples_added(QObject* segment, uint64_t start_sample,
+ void on_samples_added(uint64_t segment_id, uint64_t start_sample,
uint64_t end_sample);
void on_data_updated();