From ae908a70cecebb2cac8354a3b4d8967af847bd3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Date: Sun, 15 Oct 2023 19:09:34 +0200 Subject: [PATCH] audio: don't block on lock in ao_read_data ao_read_data() is used by pull AOs potentially from threads managed by external libraries. These threads can be sensitive to blocking. For example the pipewire ao is using a realtime thread for the callbacks. --- audio/out/buffer.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/audio/out/buffer.c b/audio/out/buffer.c index c0457ba279..e23e4cf108 100644 --- a/audio/out/buffer.c +++ b/audio/out/buffer.c @@ -184,7 +184,8 @@ int ao_read_data(struct ao *ao, void **data, int samples, int64_t out_time_ns) struct buffer_state *p = ao->buffer_state; assert(!ao->driver->write); - pthread_mutex_lock(&p->lock); + if (pthread_mutex_trylock(&p->lock)) + return 0; int pos = read_buffer(ao, data, samples, &(bool){0});