loop: always place the invoke item in the queue

Always place the invoke item in the queue and then either signal the
other thread or flush the queue when not already flushing.
This commit is contained in:
Wim Taymans 2020-11-16 15:16:20 +01:00
parent 9f9be7d7f2
commit 0d9cc9e36e

View file

@ -136,6 +136,7 @@ static void flush_items(struct impl *impl)
item = SPA_MEMBER(impl->buffer_data, index & (DATAS_SIZE - 1), struct invoke_item);
block = item->block;
spa_log_trace(impl->log, NAME " %p: flush item %p", impl, item);
item->res = item->func ? item->func(&impl->loop,
true, item->seq, item->data, item->size,
item->user_data) : 0;
@ -164,11 +165,6 @@ loop_invoke(void *object,
bool in_thread = pthread_equal(impl->thread, pthread_self());
struct invoke_item *item;
int res;
if (in_thread && !impl->flushing) {
flush_items(impl);
res = func ? func(&impl->loop, false, seq, data, size, user_data) : 0;
} else {
int32_t filled;
uint32_t avail, idx, offset, l0;
@ -208,7 +204,12 @@ loop_invoke(void *object,
spa_ringbuffer_write_update(&impl->buffer, idx + item->item_size);
if (in_thread) {
if (!impl->flushing)
flush_items(impl);
} else {
loop_signal_event(impl, impl->wakeup);
}
if (block) {
uint64_t count = 1;
@ -229,7 +230,6 @@ loop_invoke(void *object,
else
res = 0;
}
}
return res;
}