SignalBase: Don't terminate conversion when there's no data
authorSoeren Apel <soeren@apelpie.net>
Tue, 2 Jan 2018 10:07:36 +0000 (11:07 +0100)
committerUwe Hermann <uwe@hermann-uwe.de>
Tue, 9 Jan 2018 23:33:54 +0000 (00:33 +0100)
Instead of terminating, we wait instead.
We do this because SignalBase::on_samples_added() somehow doesn't
reliably see that there's no conversion thread active anymore.
conversion_thread_.joinable() returns true when the thread was
already terminated for whatever reason, resulting in on_samples_added()
trying to notify a non-existant thread.

pv/data/signalbase.cpp

index 26e01d05828858e1e1e1e00df28ee3162f5c3018..018e4a2733fca8f813efeff6f9b9c0fd1dd6a9f6 100644 (file)
@@ -542,13 +542,19 @@ void SignalBase::conversion_thread_proc()
        if (conversion_is_a2l()) {
                analog_data = dynamic_pointer_cast<Analog>(data_);
 
-               if (analog_data->analog_segments().size() == 0)
-                       return;
+               if (analog_data->analog_segments().size() == 0) {
+                       unique_lock<mutex> input_lock(conversion_input_mutex_);
+                       conversion_input_cond_.wait(input_lock);
+               }
 
        } else
                // Currently, we only handle A2L conversions
                return;
 
+       // If we had to wait for input data, we may have been notified to terminate
+       if (conversion_interrupt_)
+               return;
+
        uint32_t segment_id = 0;
 
        AnalogSegment *asegment = analog_data->analog_segments().front().get();