From 0009fcddf6c3f9c64c629e4bf086a1677ff2db1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Nettingsmeier?= Date: Sat, 16 Feb 2019 00:53:04 +0000 Subject: [PATCH] Revert "Remove client_mutex, since JACK opening and closing is now single-threaded." That was a bit too optimistic, I guess. Must understand more about the rest of shairport-sync. Fixes spurious segfault on program termination with CTRL-C that does not happen in gdb :) This reverts commit 8e46c727d59334b87ea0f639160e92349f5c81d1. --- audio_jack.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/audio_jack.c b/audio_jack.c index 8d176759..ec004861 100644 --- a/audio_jack.c +++ b/audio_jack.c @@ -33,6 +33,7 @@ static const int bytes_per_frame = 4; #define buffer_size (44100 * 4 * bytes_per_frame) static pthread_mutex_t buffer_mutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t client_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_t *open_client_if_necessary_thread = NULL; @@ -174,6 +175,7 @@ int jack_init(__attribute__((unused)) int argc, __attribute__((unused)) char **a jack_set_error_function(default_jack_error_callback); jack_set_info_function(default_jack_info_callback); + pthread_mutex_lock(&client_mutex); jack_status_t status; client = jack_client_open(config.jack_client_name, JackNoStartServer, &status); if (!client) { @@ -194,15 +196,18 @@ int jack_init(__attribute__((unused)) int argc, __attribute__((unused)) char **a } else { debug(2, "JACK client %s activated sucessfully.", config.jack_client_name); } + pthread_mutex_unlock(&client_mutex); return 0; } void jack_deinit() { + pthread_mutex_lock(&client_mutex); if (jack_deactivate(client)) debug(1, "Error deactivating jack client"); if (jack_client_close(client)) debug(1, "Error closing jack client"); + pthread_mutex_unlock(&client_mutex); jack_ringbuffer_free(jackbuf); }