From fe89c96185dba8ccf02b6b3d0994c2e149198c73 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sun, 20 Oct 2013 13:52:09 +0100 Subject: [PATCH] Implemented a global decode lock to prevent concurrent decode --- pv/data/decoder.cpp | 4 ++++ pv/data/decoder.h | 9 +++++++++ 2 files changed, 13 insertions(+) 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; -- 2.30.2