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.
This commit is contained in:
Wim Taymans 2020-09-17 11:45:25 +02:00
parent e9fd38512e
commit a9c0435317

View file

@ -80,6 +80,8 @@ struct impl {
struct spa_ringbuffer buffer; struct spa_ringbuffer buffer;
uint8_t buffer_data[DATAS_SIZE]; uint8_t buffer_data[DATAS_SIZE];
unsigned int flushing:1;
}; };
struct source_impl { struct source_impl {
@ -126,6 +128,7 @@ static void flush_items(struct impl *impl, bool async)
uint32_t index; uint32_t index;
int res; int res;
impl->flushing = true;
while (spa_ringbuffer_get_read_index(&impl->buffer, &index) > 0) { while (spa_ringbuffer_get_read_index(&impl->buffer, &index) > 0) {
struct invoke_item *item; struct invoke_item *item;
bool block; bool block;
@ -145,6 +148,7 @@ static void flush_items(struct impl *impl, bool async)
impl, spa_strerror(res)); impl, spa_strerror(res));
} }
} }
impl->flushing = false;
} }
static int static int
@ -161,7 +165,7 @@ loop_invoke(void *object,
struct invoke_item *item; struct invoke_item *item;
int res; int res;
if (in_thread) { if (in_thread && !impl->flushing) {
flush_items(impl, false); flush_items(impl, false);
res = func ? func(&impl->loop, false, seq, data, size, user_data) : 0; res = func ? func(&impl->loop, false, seq, data, size, user_data) : 0;
} else { } else {