Skip to content
This repository has been archived by the owner on Mar 27, 2020. It is now read-only.

Commit

Permalink
no more crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
Skrylar committed Jan 14, 2019
1 parent f01f0fe commit d263f3f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/jack-audio-module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
12 changes: 5 additions & 7 deletions src/skjack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<JackAudioModule*> g_audio_modules;
std::atomic<unsigned int> 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<std::mutex> lock(g_audio_modules_mutex);

for (auto itr = g_audio_modules.begin();
itr != g_audio_modules.end();
Expand Down

0 comments on commit d263f3f

Please sign in to comment.