diff options
author | Vadim Yanitskiy <axilirator@gmail.com> | 2017-09-01 15:15:45 +0700 |
---|---|---|
committer | Vadim Yanitskiy <axilirator@gmail.com> | 2017-12-31 12:20:59 +0100 |
commit | 304fa73421a7c6ca5dcf36145f40c77af7df1de7 (patch) | |
tree | 990fa6ad9ff7cb176fa5713a4f3f8a7f35b54efe | |
parent | 3be9c7ae3c22f3e91c4e54b57a07b722dd4fb73f (diff) |
procqueue: store output buffers inside queue items
An output buffer belongs to its queue item, so it will be more
correctly to store its pointer inside the osmo_gapk_pq_item.
-rw-r--r-- | include/osmocom/gapk/procqueue.h | 3 | ||||
-rw-r--r-- | src/procqueue.c | 12 |
2 files changed, 8 insertions, 7 deletions
diff --git a/include/osmocom/gapk/procqueue.h b/include/osmocom/gapk/procqueue.h index b4aa857..6921b51 100644 --- a/include/osmocom/gapk/procqueue.h +++ b/include/osmocom/gapk/procqueue.h @@ -29,6 +29,8 @@ struct osmo_gapk_pq_item { unsigned int len_out; /*! opaque state */ void *state; + /*! buffer for output data */ + uint8_t *buf; /*! call-back for actual format conversion function * \param[in] state opaque state pointer * \param[out] out caller-allocated buffer for output data @@ -45,7 +47,6 @@ struct osmo_gapk_pq_item { struct osmo_gapk_pq { unsigned n_items; struct osmo_gapk_pq_item *items[MAX_PQ_ITEMS]; - void *buffers[MAX_PQ_ITEMS + 1]; }; /* Processing queue management */ diff --git a/src/procqueue.c b/src/procqueue.c index f377db1..0176317 100644 --- a/src/procqueue.c +++ b/src/procqueue.c @@ -45,12 +45,11 @@ osmo_gapk_pq_destroy(struct osmo_gapk_pq *pq) continue; if (pq->items[i]->exit) pq->items[i]->exit(pq->items[i]->state); + + free(pq->items[i]->buf); free(pq->items[i]); } - for (i=0; i<pq->n_items-1; i++) - free(pq->buffers[i]); /* free is NULL safe */ - free(pq); } @@ -103,8 +102,9 @@ osmo_gapk_pq_prepare(struct osmo_gapk_pq *pq) * known buffer size */ if (!buf_size) buf_size = VAR_BUF_SIZE; - pq->buffers[i] = malloc(buf_size); - if (!pq->buffers[i]) + + item->buf = malloc(buf_size); + if (!item->buf) return -ENOMEM; } else{ if (item->len_out) @@ -134,7 +134,7 @@ osmo_gapk_pq_execute(struct osmo_gapk_pq *pq) int rv; struct osmo_gapk_pq_item *item = pq->items[i]; - buf = i < (pq->n_items-1) ? pq->buffers[i] : NULL; + buf = i < (pq->n_items-1) ? item->buf : NULL; rv = item->proc(item->state, buf, buf_prev, len_prev); if (rv < 0) { |