diff --git a/source/backend/engine/CarlaEngine.cpp b/source/backend/engine/CarlaEngine.cpp index 701423358..60a2b3368 100644 --- a/source/backend/engine/CarlaEngine.cpp +++ b/source/backend/engine/CarlaEngine.cpp @@ -1498,7 +1498,7 @@ void CarlaEngine::processRack(float* inBuf[2], float* outBuf[2], const uint32_t { CarlaPlugin* const plugin = kData->plugins[i].plugin; - if (plugin == nullptr || ! plugin->enabled()) + if (plugin == nullptr || ! plugin->enabled() || ! plugin->tryLock()) continue; if (processed) @@ -1517,6 +1517,7 @@ void CarlaEngine::processRack(float* inBuf[2], float* outBuf[2], const uint32_t // process plugin->initBuffers(); plugin->process(inBuf, outBuf, frames); + plugin->unlock(); #if 0 // if plugin has no audio inputs, add previous buffers diff --git a/source/backend/engine/CarlaEngineJack.cpp b/source/backend/engine/CarlaEngineJack.cpp index 9ceaf7936..d3711723b 100644 --- a/source/backend/engine/CarlaEngineJack.cpp +++ b/source/backend/engine/CarlaEngineJack.cpp @@ -886,10 +886,11 @@ protected: #ifdef BUILD_BRIDGE CarlaPlugin* const plugin = getPluginUnchecked(0); - if (plugin && plugin->enabled()) + if (plugin && plugin->enabled() && plugin->tryLock()) { plugin->initBuffers(); processPlugin(plugin, nframes); + plugin->unlock(); } #else if (fOptions.processMode == PROCESS_MODE_SINGLE_CLIENT) @@ -898,10 +899,11 @@ protected: { CarlaPlugin* const plugin = getPluginUnchecked(i); - if (plugin && plugin->enabled()) + if (plugin && plugin->enabled() && plugin->tryLock()) { plugin->initBuffers(); processPlugin(plugin, nframes); + plugin->unlock(); } } } @@ -1616,13 +1618,14 @@ private: { CarlaPlugin* const plugin = (CarlaPlugin*)arg; - if (plugin != nullptr && plugin->enabled()) + if (plugin != nullptr && plugin->enabled() && plugin->tryLock()) { CarlaEngineJack* const engine = (CarlaEngineJack*)CarlaPluginGetEngine(plugin); plugin->initBuffers(); engine->saveTransportInfo(); engine->processPlugin(plugin, nframes); + plugin->unlock(); } return 0; diff --git a/source/backend/plugin/CarlaPlugin.cpp b/source/backend/plugin/CarlaPlugin.cpp index f9f1321de..8add600c2 100644 --- a/source/backend/plugin/CarlaPlugin.cpp +++ b/source/backend/plugin/CarlaPlugin.cpp @@ -95,6 +95,8 @@ CarlaPlugin::~CarlaPlugin() { carla_debug("CarlaPlugin::~CarlaPlugin()"); + kData->mutex.lock(); + // Remove client and ports if (kData->client != nullptr) { @@ -118,6 +120,7 @@ CarlaPlugin::~CarlaPlugin() kData->prog.clear(); kData->midiprog.clear(); kData->custom.clear(); + kData->mutex.unlock(); libClose(); @@ -1899,11 +1902,10 @@ CarlaPlugin::ScopedDisabler::ScopedDisabler(CarlaPlugin* const plugin) carla_debug("CarlaPlugin::ScopedDisabler(%p)", plugin); CARLA_ASSERT(plugin != nullptr); + plugin->kData->mutex.lock(); + if (plugin->fEnabled) - { plugin->fEnabled = false; - plugin->kData->engine->waitForProccessEnd(plugin->id()); - } if (plugin->kData->client->isActive()) plugin->kData->client->deactivate(); @@ -1915,6 +1917,7 @@ CarlaPlugin::ScopedDisabler::~ScopedDisabler() kPlugin->fEnabled = true; kPlugin->kData->client->activate(); + kPlugin->kData->mutex.unlock(); } // -------------------------------------------------------------------