From a91502b3e09d95be1ab9b90fad91ea2cab2dec52 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 19 Jul 2021 10:12:15 +0200 Subject: [PATCH] loop: improve invoke avail check First calculate the size of the aligned payload and then check if we can fit this aligned payload in the remaining space in the ringbuffer. Otherwise we might be able to fit the item + payload in the remaining space but then place the alignment bytes at the begginning, which would break alignment of the next invoke_item struct. --- spa/plugins/support/loop.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spa/plugins/support/loop.c b/spa/plugins/support/loop.c index 5a052e8d8..00db8f847 100644 --- a/spa/plugins/support/loop.c +++ b/spa/plugins/support/loop.c @@ -192,13 +192,13 @@ loop_invoke(void *object, item->size = size; item->block = block && !in_thread; item->user_data = user_data; + item->item_size = SPA_ROUND_UP_N(sizeof(struct invoke_item) + size, 8); spa_log_trace(impl->log, NAME " %p: add item %p filled:%d", impl, item, filled); - if (l0 > sizeof(struct invoke_item) + size) { + if (l0 >= item->item_size) { /* item + size fit in current ringbuffer idx */ item->data = SPA_PTROFF(item, sizeof(struct invoke_item), void); - item->item_size = SPA_ROUND_UP_N(sizeof(struct invoke_item) + size, 8); if (l0 < sizeof(struct invoke_item) + item->item_size) { /* not enough space for next invoke_item, fill up till the end * so that the next item will be at the start */