From: Soeren Apel Date: Tue, 9 Feb 2016 10:58:36 +0000 (+0100) Subject: DecoderStack: Make decoder sessions terminate after running X-Git-Tag: pulseview-0.4.0~342 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=cc10c40992278034a7d7648d34f19ff6743710db;p=pulseview.git DecoderStack: Make decoder sessions terminate after running 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. --- diff --git a/pv/data/decoderstack.cpp b/pv/data/decoderstack.cpp index 2668df29..51d4bae0 100644 --- a/pv/data/decoderstack.cpp +++ b/pv/data/decoderstack.cpp @@ -282,11 +282,22 @@ uint64_t DecoderStack::max_sample_count() const optional DecoderStack::wait_for_data() const { unique_lock 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_); }