From a9c0435317a2c75f76ac672d2ccc44fb02e2faa4 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 17 Sep 2020 11:45:25 +0200 Subject: [PATCH] loop: don't recursively flush If we are already in the loop thread and flushing, this means we added a new invoke item on the list from a callback. Place the item on the queue and let the flush code take care of it after the callback completes. Required to fix some issues with draining in pulse where a stream is destroyed from the drained callback which then invokes a pause. --- spa/plugins/support/loop.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spa/plugins/support/loop.c b/spa/plugins/support/loop.c index f9c166531..160f0c275 100644 --- a/spa/plugins/support/loop.c +++ b/spa/plugins/support/loop.c @@ -80,6 +80,8 @@ struct impl { struct spa_ringbuffer buffer; uint8_t buffer_data[DATAS_SIZE]; + + unsigned int flushing:1; }; struct source_impl { @@ -126,6 +128,7 @@ static void flush_items(struct impl *impl, bool async) uint32_t index; int res; + impl->flushing = true; while (spa_ringbuffer_get_read_index(&impl->buffer, &index) > 0) { struct invoke_item *item; bool block; @@ -145,6 +148,7 @@ static void flush_items(struct impl *impl, bool async) impl, spa_strerror(res)); } } + impl->flushing = false; } static int @@ -161,7 +165,7 @@ loop_invoke(void *object, struct invoke_item *item; int res; - if (in_thread) { + if (in_thread && !impl->flushing) { flush_items(impl, false); res = func ? func(&impl->loop, false, seq, data, size, user_data) : 0; } else {