From a3cb425ca957bad3d4862ac38b111e71f7bcb318 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 28 Jun 2010 23:07:05 +0000 Subject: [PATCH] Fix race causing MIDI tracer to stop working when master record state is changed. git-svn-id: svn://localhost/ardour2/branches/3.0@7320 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/midi_tracer.cc | 8 ++++---- gtk2_ardour/midi_tracer.h | 8 +++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/gtk2_ardour/midi_tracer.cc b/gtk2_ardour/midi_tracer.cc index a9f38b52ff..565d0f4911 100644 --- a/gtk2_ardour/midi_tracer.cc +++ b/gtk2_ardour/midi_tracer.cc @@ -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 buf (text.get_buffer()); diff --git a/gtk2_ardour/midi_tracer.h b/gtk2_ardour/midi_tracer.h index 47f1738243..fb5943370d 100644 --- a/gtk2_ardour/midi_tracer.h +++ b/gtk2_ardour/midi_tracer.h @@ -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 fifo; Pool buffer_pool; static const size_t buffer_size = 256;