From 6ab10237cdd412fb5547642a561d34a797e1991c Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 6 May 2024 16:23:07 +0200 Subject: [PATCH] alsa: use semaphore semantics for the eventfd Because we write from multiple threads, a thread might write a second wakeup and a concurrent thread might remove all wakeups before seeing it's error and retrying, which would leave the eventfd in a wrong state. With a semaphore, things balance out and the eventfd always ends up in a consistent state. --- pipewire-alsa/alsa-plugins/pcm_pipewire.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pipewire-alsa/alsa-plugins/pcm_pipewire.c b/pipewire-alsa/alsa-plugins/pcm_pipewire.c index f1785b7f4..8ae2e6012 100644 --- a/pipewire-alsa/alsa-plugins/pcm_pipewire.c +++ b/pipewire-alsa/alsa-plugins/pcm_pipewire.c @@ -1262,7 +1262,8 @@ static int snd_pcm_pipewire_open(snd_pcm_t **pcmp, pw_core_add_listener(pw->core, &pw->core_listener, &core_events, pw); pw_thread_loop_unlock(pw->main_loop); - pw->fd = spa_system_eventfd_create(pw->system, SPA_FD_CLOEXEC | SPA_FD_NONBLOCK); + pw->fd = spa_system_eventfd_create(pw->system, + SPA_FD_EVENT_SEMAPHORE | SPA_FD_CLOEXEC | SPA_FD_NONBLOCK); if (pw->fd < 0) { err = pw->fd; goto error;