From: Joel Holdsworth Date: Sun, 20 Oct 2013 12:52:09 +0000 (+0100) Subject: Implemented a global decode lock to prevent concurrent decode X-Git-Tag: pulseview-0.2.0~233 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=fe89c96185dba8ccf02b6b3d0994c2e149198c73;p=pulseview.git Implemented a global decode lock to prevent concurrent decode --- diff --git a/pv/data/decoder.cpp b/pv/data/decoder.cpp index 8a84fd4d..133fcd19 100644 --- a/pv/data/decoder.cpp +++ b/pv/data/decoder.cpp @@ -43,6 +43,8 @@ const double Decoder::DecodeMargin = 1.0; const double Decoder::DecodeThreshold = 0.2; const int64_t Decoder::DecodeChunkLength = 4096; +mutex Decoder::_global_decode_mutex; + Decoder::Decoder(const srd_decoder *const dec, std::map > probes, @@ -191,6 +193,8 @@ void Decoder::decode_proc(shared_ptr data) !this_thread::interruption_requested() && i < sample_count; i += DecodeChunkLength) { + lock_guard decode_lock(_global_decode_mutex); + const int64_t chunk_end = min( i + DecodeChunkLength, sample_count); snapshot->get_samples(chunk, i, chunk_end); diff --git a/pv/data/decoder.h b/pv/data/decoder.h index 09002ac9..b8608d2c 100644 --- a/pv/data/decoder.h +++ b/pv/data/decoder.h @@ -96,6 +96,15 @@ signals: void new_decode_data(); private: + + /** + * This mutex prevents more than one decode operation occuring + * concurrently. + * @todo A proper solution should be implemented to allow multiple + * decode operations. + */ + static boost::mutex _global_decode_mutex; + const srd_decoder *const _decoder; std::map > _probes;