From 893b46c0d03344a0756de6908641b57c29c4e76a Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 3 Aug 2023 10:08:11 +0200 Subject: [PATCH] module-x11-bell: protect libcanberra calls with a mutex The libcanberra calls use libtool, which can not be called from multiple threads at the same time. Use a global lock to serialize these calls in the x11-bell module. This is only a problem when multiple libcanberra calls are made in the same process, such when you load the x11-bell module twice. There is no guarantee that other libcanberra calls will not interfere but for now we only use libcanberra here. Fixes #2834 --- src/modules/module-x11-bell.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/modules/module-x11-bell.c b/src/modules/module-x11-bell.c index b4f238764..3359ce845 100644 --- a/src/modules/module-x11-bell.c +++ b/src/modules/module-x11-bell.c @@ -62,6 +62,10 @@ PW_LOG_TOPIC_STATIC(mod_topic, "mod." NAME); #define PW_LOG_TOPIC_DEFAULT mod_topic +/* libcanberra is not thread safe when doing ca_context_create() + * and so we need a global lock */ +static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; + struct impl { struct pw_context *context; struct pw_thread_loop *thread_loop; @@ -83,6 +87,7 @@ static int play_sample(struct impl *impl) ca_context *ca; int res; + pthread_mutex_lock(&lock); if (impl->properties) sample = pw_properties_get(impl->properties, "sample.name"); if (sample == NULL) @@ -113,6 +118,7 @@ static int play_sample(struct impl *impl) exit_destroy: ca_context_destroy(ca); exit: + pthread_mutex_unlock(&lock); return res; }