]> sigrok.org Git - pulseview.git/commitdiff
Fix #1629 by not reallocating DecodeSegments
authorSoeren Apel <redacted>
Mon, 23 Nov 2020 22:49:11 +0000 (23:49 +0100)
committerSoeren Apel <redacted>
Mon, 23 Nov 2020 22:49:11 +0000 (23:49 +0100)
Doing so called the empty DecodeSegment copy constructor,
creating empty DecodeSegment instances.

Also fixes an off-by-one bug that prevented the final input
segment from being processed.

pv/data/decodesignal.cpp
pv/data/decodesignal.hpp

index bda8d51ee864cc97e42ffde55424a60331260a1e..640e58148ef751e3aa7557dca2d7af5d526c2240 100644 (file)
@@ -1173,14 +1173,12 @@ void DecodeSignal::logic_mux_proc()
                                        logic_mux_data_->push_segment(output_segment);
 
                                        output_segment->set_samplerate(get_input_samplerate(segment_id));
+                               } else {
+                                       // Wait for more input data if we're processing the currently last segment
+                                       unique_lock<mutex> logic_mux_lock(logic_mux_mutex_);
+                                       logic_mux_cond_.wait(logic_mux_lock);
                                }
                        }
-
-                       if (segment_id == (get_input_segment_count() - 1)) {
-                               // Wait for more input data if we're processing the currently last segment
-                               unique_lock<mutex> logic_mux_lock(logic_mux_mutex_);
-                               logic_mux_cond_.wait(logic_mux_lock);
-                       }
                }
        } while (!logic_mux_interrupt_);
 }
@@ -1305,14 +1303,13 @@ void DecodeSignal::decode_proc()
                                        // All segments have been processed
                                        if (!decode_interrupt_)
                                                decode_finished();
+
+                                       // Wait for more input data
+                                       unique_lock<mutex> input_wait_lock(input_mutex_);
+                                       decode_input_cond_.wait(input_wait_lock);
                                }
                        }
 
-                       if (current_segment_id_ == (logic_mux_data_->logic_segments().size() - 1)) {
-                               // Wait for more input data if we're processing the currently last segment
-                               unique_lock<mutex> input_wait_lock(input_mutex_);
-                               decode_input_cond_.wait(input_wait_lock);
-                       }
                }
        } while (!decode_interrupt_);
 }
index fad3db78548457d25e61f9b4f7dc0bf8042243cf..f4783be22706ee18a9ce11b2c23d2b2e17d95b6c 100644 (file)
@@ -26,6 +26,7 @@
 #include <unordered_set>
 #include <vector>
 
+#include <QDebug>
 #include <QSettings>
 
 #include <libsigrokdecode/libsigrokdecode.h>
@@ -79,7 +80,7 @@ struct DecodeSegment
        // Constructor is a no-op
        DecodeSegment() { };
        // Copy constructor is a no-op
-       DecodeSegment(DecodeSegment&& ds) { (void)ds; };
+       DecodeSegment(DecodeSegment&& ds) { (void)ds; qCritical() << "Empty DecodeSegment copy constructor called"; };
 
        map<const Row*, RowData> annotation_rows;  // Note: Row is the same for all segments while RowData is not
        pv::util::Timestamp start_time;
@@ -246,7 +247,7 @@ private:
        vector< shared_ptr<Decoder> > stack_;
        bool stack_config_changed_;
 
-       vector<DecodeSegment> segments_;
+       deque<DecodeSegment> segments_;
        uint32_t current_segment_id_;
 
        mutable mutex input_mutex_, output_mutex_, decode_pause_mutex_, logic_mux_mutex_;