Fix VST state-lock SNAFU (effSetChunk and process are exclusive)
authorRobin Gareus <robin@gareus.org>
Mon, 14 Nov 2016 20:05:36 +0000 (21:05 +0100)
committerRobin Gareus <robin@gareus.org>
Mon, 14 Nov 2016 20:06:18 +0000 (21:06 +0100)
gtk2_ardour/linux_vst_gui_support.cc
libs/ardour/ardour/vst_plugin.h
libs/ardour/ardour/vst_types.h
libs/ardour/vst_plugin.cc
libs/fst/vstwin.c

index a2f637a26c6e5446f47337504dbe89bc14fd0996..fe85ea188ef5293f4fa67b9ac972f1626f0021ae 100644 (file)
@@ -320,8 +320,10 @@ maybe_set_program (VSTState* vstfx)
        }
 
        if (vstfx->want_chunk == 1) {
+               pthread_mutex_lock (&vstfx->state_lock);
                vstfx->plugin->dispatcher (vstfx->plugin, 24 /* effSetChunk */, 1, vstfx->wanted_chunk_size, vstfx->wanted_chunk, 0);
                vstfx->want_chunk = 0;
+               pthread_mutex_unlock (&vstfx->state_lock);
        }
 }
 
index 182b432692770d9d28e55051b92f27d904939f0c..2a8b4dc9a1fc83afc72c9766d3a7276b6566ac25 100644 (file)
@@ -120,8 +120,6 @@ protected:
        framepos_t _transport_frame;
        float      _transport_speed;
        mutable std::map <uint32_t, float> _parameter_defaults;
-
-       Glib::Threads::Mutex _state_lock;
 };
 
 }
index 936cab6173fb1120da85f67b896044e5ead94bdf..0b8bcb62736d2637fba90c0668ff606dd705f7d0 100644 (file)
@@ -129,6 +129,7 @@ struct LIBARDOUR_API _VSTState
 
        struct _VSTState * next;
        pthread_mutex_t    lock;
+       pthread_mutex_t    state_lock;
        pthread_cond_t     window_status_change;
        pthread_cond_t     plugin_dispatcher_called;
        pthread_cond_t     window_created;
@@ -136,6 +137,7 @@ struct LIBARDOUR_API _VSTState
 
        void init () {
                pthread_mutex_init (&lock, 0);
+               pthread_mutex_init (&state_lock, 0);
                pthread_cond_init (&window_status_change, 0);
                pthread_cond_init (&plugin_dispatcher_called, 0);
                pthread_cond_init (&window_created, 0);
index 8214d0be812a1c7f1a9d95371f205695db36058d..1fd8d8cd55c5be61d12110342f677377540bd03d 100644 (file)
@@ -172,8 +172,9 @@ VSTPlugin::set_chunk (gchar const * data, bool single)
        int r = 0;
        guchar* raw_data = g_base64_decode (data, &size);
        {
-               Glib::Threads::Mutex::Lock lm (_lock);
+               pthread_mutex_lock (&_state->state_lock);
                r = _plugin->dispatcher (_plugin, 24 /* effSetChunk */, single ? 1 : 0, size, raw_data, 0);
+               pthread_mutex_unlock (&_state->state_lock);
        }
        g_free (raw_data);
        return r;
@@ -566,8 +567,7 @@ VSTPlugin::connect_and_run (BufferSet& bufs,
 {
        Plugin::connect_and_run(bufs, start, end, speed, in_map, out_map, nframes, offset);
 
-       Glib::Threads::Mutex::Lock lm (_state_lock, Glib::Threads::TRY_LOCK);
-       if (!lm.locked()) {
+       if (pthread_mutex_trylock (&_state->state_lock)) {
                /* by convention 'effSetChunk' should not be called while processing
                 * http://www.reaper.fm/sdk/vst/vst_ext.php
                 *
@@ -645,6 +645,7 @@ VSTPlugin::connect_and_run (BufferSet& bufs,
        _plugin->processReplacing (_plugin, &ins[0], &outs[0], nframes);
        _midi_out_buf = 0;
 
+       pthread_mutex_unlock (&_state->state_lock);
        return 0;
 }
 
index 7f748c6db65b1162ff4c8ef5954c77656efe0bf5..1e053d1ae7198272c108669f2ffd7e31c4c158d9 100644 (file)
@@ -92,8 +92,10 @@ maybe_set_program (VSTState* fst)
                // XXX check
                // 24 == audioMasterGetAutomationState,
                // 48 == audioMasterGetChunkFile
+               pthread_mutex_lock (&vstfx->state_lock);
                fst->plugin->dispatcher (fst->plugin, 24 /* effSetChunk */, 1, fst->wanted_chunk_size, fst->wanted_chunk, 0);
                fst->want_chunk = 0;
+               pthread_mutex_unlock (&vstfx->state_lock);
        }
 }