diff --git a/src/jack-audio-module.cc b/src/jack-audio-module.cc index ed2c5a3..d9cdebe 100644 --- a/src/jack-audio-module.cc +++ b/src/jack-audio-module.cc @@ -110,6 +110,8 @@ void JackAudioModule::globally_unregister() { } JackAudioModule::~JackAudioModule() { + globally_unregister(); + /* and kill our port */ if (!g_jack_client.alive()) return; for (int i = 0; i < JACK_PORTS; i++) { diff --git a/src/skjack.cc b/src/skjack.cc index f415f52..5fc4db2 100644 --- a/src/skjack.cc +++ b/src/skjack.cc @@ -4,19 +4,17 @@ Plugin *plugin; jaq::client g_jack_client; std::condition_variable g_jack_cv; - -// TODO: consider protecting this with a mutex -// this would be optimal for correctness, but in practice this gets modified -// very infrequently and nobody cares if we miss one or two audio frames right -// after creating or destroying a module... std::mutex g_audio_modules_mutex; std::vector g_audio_modules; std::atomic g_audio_blocked(0); int on_jack_process(jack_nframes_t nframes, void *) { if (!g_jack_client.alive()) return 1; - /* audio modules vector is blocked; we have to skip this cycle */ - if (!g_audio_modules_mutex.try_lock()) return 0; + /* JACK doesn't like us doing things that might block for a "long time." + * this mutex is only locked to process audio, and add or remove modules, + * and i don't think anyone is going to mind an xrun on those rare conditions + */ + std::unique_lock lock(g_audio_modules_mutex); for (auto itr = g_audio_modules.begin(); itr != g_audio_modules.end();