From 5e323333cf128bc159c3bac9e412ff8c6de41693 Mon Sep 17 00:00:00 2001 From: Kevin Mitchell Date: Wed, 17 Jun 2020 01:55:18 -0700 Subject: [PATCH] audio: don't lock ao_control for pull mode drivers The pull mode APIs were previously required to have thread-safe ao_controls. However, locks were added in b83bdd1 for parity with push mode. This introduced deadlocks in ao_wasapi. Instead, only lock ao_control for the push mode APIs. fixes #7787 See also #7832, #7811. We'll wait for feedback to see if those should also be closed. --- audio/out/buffer.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/audio/out/buffer.c b/audio/out/buffer.c index dc053c3e2c..2992180854 100644 --- a/audio/out/buffer.c +++ b/audio/out/buffer.c @@ -288,9 +288,14 @@ int ao_control(struct ao *ao, enum aocontrol cmd, void *arg) struct buffer_state *p = ao->buffer_state; int r = CONTROL_UNKNOWN; if (ao->driver->control) { - pthread_mutex_lock(&p->lock); + // Only need to lock in push mode. + if (ao->driver->write) + pthread_mutex_lock(&p->lock); + r = ao->driver->control(ao, cmd, arg); - pthread_mutex_unlock(&p->lock); + + if (ao->driver->write) + pthread_mutex_unlock(&p->lock); } return r; }