procqueue.c: rely on item type instead of its position

In the osmo_gapk_pq_prepare() we do allocate an item's buffer
conditionally, only when its type is not sink, because an output
buffer is not required for sink.

Let's use a bit more elegant way to check, whether item is sink.

Change-Id: I770a1d02273d9d8301a9e4ec72426fb8f4060277
This commit is contained in:
Vadim Yanitskiy 2018-06-29 20:31:21 +07:00
parent 379b657c57
commit 6d0156b89a
1 changed files with 15 additions and 13 deletions

View File

@ -159,25 +159,27 @@ int
osmo_gapk_pq_prepare(struct osmo_gapk_pq *pq)
{
struct osmo_gapk_pq_item *item;
unsigned int buf_size;
/* Iterate over all items in queue */
llist_for_each_entry(item, &pq->items, list) {
/* The sink item doesn't require an output buffer */
if (item->list.next != &pq->items) {
unsigned int buf_size = item->len_out;
if (item->type == OSMO_GAPK_ITEM_TYPE_SINK)
continue;
/**
* Use maximum known buffer size
* for variable-length codec output
*/
if (!buf_size)
buf_size = VAR_BUF_SIZE;
buf_size = item->len_out;
/* Allocate memory for an output buffer */
item->buf = talloc_named_const(item, buf_size, ".buffer");
if (!item->buf)
return -ENOMEM;
}
/**
* Use maximum known buffer size
* for variable-length codec output
*/
if (!buf_size)
buf_size = VAR_BUF_SIZE;
/* Allocate memory for an output buffer */
item->buf = talloc_named_const(item, buf_size, ".buffer");
if (!item->buf)
return -ENOMEM;
}
return 0;