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.
This commit is contained in:
Wim Taymans 2021-07-19 10:12:15 +02:00
parent 7f4fa64291
commit a91502b3e0

View file

@ -192,13 +192,13 @@ loop_invoke(void *object,
item->size = size; item->size = size;
item->block = block && !in_thread; item->block = block && !in_thread;
item->user_data = user_data; 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); 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 + size fit in current ringbuffer idx */
item->data = SPA_PTROFF(item, sizeof(struct invoke_item), void); 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) { if (l0 < sizeof(struct invoke_item) + item->item_size) {
/* not enough space for next invoke_item, fill up till the end /* not enough space for next invoke_item, fill up till the end
* so that the next item will be at the start */ * so that the next item will be at the start */