]> sigrok.org Git - pulseview.git/commitdiff
Implemented a global decode lock to prevent concurrent decode
authorJoel Holdsworth <redacted>
Sun, 20 Oct 2013 12:52:09 +0000 (13:52 +0100)
committerJoel Holdsworth <redacted>
Wed, 23 Oct 2013 23:12:27 +0000 (00:12 +0100)
pv/data/decoder.cpp
pv/data/decoder.h

index 8a84fd4d8f4e9032a3876eaeb9ee405587fa9602..133fcd19d44b1f9a0c9fec43b94283a418628cf9 100644 (file)
@@ -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<const srd_probe*,
                boost::shared_ptr<pv::view::LogicSignal> > probes,
@@ -191,6 +193,8 @@ void Decoder::decode_proc(shared_ptr<data::Logic> data)
                !this_thread::interruption_requested() && i < sample_count;
                i += DecodeChunkLength)
        {
+               lock_guard<mutex> decode_lock(_global_decode_mutex);
+
                const int64_t chunk_end = min(
                        i + DecodeChunkLength, sample_count);
                snapshot->get_samples(chunk, i, chunk_end);
index 09002ac911153ed06901af6ab1ba3e0927b1f4c7..b8608d2cc4290ed712722ba1e677e6383e96fb03 100644 (file)
@@ -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<const srd_probe*, boost::shared_ptr<view::LogicSignal> >
                _probes;