From a54fa5f26da997346ec9a0844f2e234b51399409 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 7 Sep 2021 17:13:15 +0200 Subject: [PATCH] jack: improve do_sync Keep track of the last scheduled sync operation and wake up listeners when it completes. The waiters also compare against the last issued sync so that when multiple syncs are pending from multiple threads, they will all wakeup instead of just one. Fixes some lockups with ardour6. --- pipewire-jack/src/pipewire-jack.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pipewire-jack/src/pipewire-jack.c b/pipewire-jack/src/pipewire-jack.c index f5403257c..dc31902b2 100644 --- a/pipewire-jack/src/pipewire-jack.c +++ b/pipewire-jack/src/pipewire-jack.c @@ -288,6 +288,7 @@ struct client { struct pw_core *core; struct spa_hook core_listener; struct pw_mempool *pool; + int pending_sync; int last_sync; int last_res; bool error; @@ -772,7 +773,8 @@ static void on_sync_reply(void *data, uint32_t id, int seq) if (id != PW_ID_CORE) return; client->last_sync = seq; - pw_thread_loop_signal(client->context.loop, false); + if (client->pending_sync == seq) + pw_thread_loop_signal(client->context.loop, false); } @@ -800,14 +802,12 @@ static const struct pw_core_events core_events = { static int do_sync(struct client *client) { - int seq; - if (pw_thread_loop_in_thread(client->context.loop)) { pw_log_warn("sync requested from callback"); return 0; } - seq = pw_proxy_sync((struct pw_proxy*)client->core, client->last_sync); + client->pending_sync = pw_proxy_sync((struct pw_proxy*)client->core, client->pending_sync); while (true) { pw_thread_loop_wait(client->context.loop); @@ -815,7 +815,7 @@ static int do_sync(struct client *client) if (client->error) return client->last_res; - if (client->last_sync == seq) + if (client->pending_sync == client->last_sync) break; } return 0;