Fix race causing MIDI tracer to stop working when master record state is changed.
authorCarl Hetherington <carl@carlh.net>
Mon, 28 Jun 2010 23:07:05 +0000 (23:07 +0000)
committerCarl Hetherington <carl@carlh.net>
Mon, 28 Jun 2010 23:07:05 +0000 (23:07 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@7320 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/midi_tracer.cc
gtk2_ardour/midi_tracer.h

index a9f38b52ff5a82c8841b4df9011a275face6e4a1..565d0f49112f2bb73f846c5d3e1dcf1c6b06d8f6 100644 (file)
@@ -25,7 +25,7 @@ MidiTracer::MidiTracer (const std::string& name, Parser& p)
        , autoscroll (true)
        , show_hex (true)
        , collect (true)
-       , update_queued (false)
+       , _update_queued (0)
        , fifo (1024)
        , buffer_pool ("miditracer", buffer_size, 1024) // 1024 256 byte buffers
        , autoscroll_button (_("Auto-Scroll"))
@@ -255,9 +255,9 @@ MidiTracer::tracer (Parser&, byte* msg, size_t len)
 
        fifo.write (&buf, 1);
 
-       if (!update_queued) {
+       if (g_atomic_int_get (&_update_queued) == 0) {
                gui_context()->call_slot (invalidator (*this), boost::bind (&MidiTracer::update, this));
-               update_queued = true;
+               g_atomic_int_inc (&_update_queued);
        }
 }
 
@@ -265,7 +265,7 @@ void
 MidiTracer::update ()
 {
        bool updated = false;
-       update_queued = false;
+       g_atomic_int_dec_and_test (&_update_queued);
 
        RefPtr<TextBuffer> buf (text.get_buffer());
 
index 47f173824345ed9cb791b7cfed5ffa018e2fd77b..fb5943370dd436acf81a5be964c51f14b4efcab2 100644 (file)
@@ -36,7 +36,13 @@ class MidiTracer : public ArdourDialog
        bool autoscroll;
        bool show_hex;
        bool collect;
-       volatile bool update_queued;
+       
+       /** Incremented when an update is requested, decremented when one is handled; hence
+        *  equal to 0 when an update is not queued.  May temporarily be negative if a
+        *  update is handled before it was noted that it had just been queued.
+        */
+       volatile gint _update_queued;
+        
        RingBuffer<char *> fifo;
        Pool buffer_pool;
        static const size_t buffer_size = 256;