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.
This commit is contained in:
Wim Taymans 2021-09-07 17:13:15 +02:00
parent c25cec230c
commit a54fa5f26d

View file

@ -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,6 +773,7 @@ static void on_sync_reply(void *data, uint32_t id, int seq)
if (id != PW_ID_CORE)
return;
client->last_sync = seq;
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;