diff options
| author | Vadim Yanitskiy <axilirator@gmail.com> | 2017-09-01 15:15:45 +0700 |
|---|---|---|
| committer | Vadim Yanitskiy <axilirator@gmail.com> | 2017-09-04 04:37:21 +0700 |
| commit | 903f14cdf48faa61996b22b68361c511c920b3b9 (patch) | |
| tree | a76c586db4629cd8109589f150c45f5c1b68a6b2 | |
| parent | 0d97f46b8757e0947304d88777706bd9a98a4c69 (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) { |
