]> sigrok.org Git - pulseview.git/commitdiff
DecoderStack: Make decoder sessions terminate after running
authorSoeren Apel <redacted>
Tue, 9 Feb 2016 10:58:36 +0000 (11:58 +0100)
committerUwe Hermann <redacted>
Thu, 11 Feb 2016 14:08:08 +0000 (15:08 +0100)
Currently, SRD sessions aren't terminating after all data
has been decoded, leaving the decode thread in a state
where it's waiting for more data.
This would be okay if an acquisition was still ongoing but
when the acquisition has been stopped, there will never be
more data. When a new acquisition is started, the previous
decode sessions will be terminated and then new ones will
be started. This is the reason why this behavior wasn't
an issue up until now.

However, the fix for #181 requires that the decode thread
terminates or else the global SRD lock will never be
released.

pv/data/decoderstack.cpp

index 2668df2937acb3e29035ab39ceffaf86953f1195..51d4bae0483ec4ca2b1fb74abae54738f680bd0d 100644 (file)
@@ -282,11 +282,22 @@ uint64_t DecoderStack::max_sample_count() const
 optional<int64_t> DecoderStack::wait_for_data() const
 {
        unique_lock<mutex> input_lock(input_mutex_);
+
+       // Do wait if we decoded all samples but we're still capturing
+       // Do not wait if we're done capturing
        while (!interrupt_ && !frame_complete_ &&
-               samples_decoded_ >= sample_count_)
+               (samples_decoded_ >= sample_count_) &&
+               (session_.get_capture_state() != Session::Stopped)) {
+
                input_cond_.wait(input_lock);
+       }
+
+       // Return value is valid if we're not aborting the decode,
        return boost::make_optional(!interrupt_ &&
-               (samples_decoded_ < sample_count_ || !frame_complete_),
+               // and there's more work to do...
+               (samples_decoded_ < sample_count_ || !frame_complete_) &&
+               // and if the end of the data hasn't been reached yet
+               (!((samples_decoded_ >= sample_count_) && (session_.get_capture_state() == Session::Stopped))),
                sample_count_);
 }