From: Gerhard Sittig Date: Sun, 15 Oct 2023 08:22:20 +0000 (+0200) Subject: feed_queue: add API to submit multiple sample values at once X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=f70db77ae6d27eea6cd9675c4eea5abf17c20765;p=libsigrok.git feed_queue: add API to submit multiple sample values at once Extend the common feed queue support API. Add a routine which accepts multiple sample values that correspond to multiple sample points. This eliminates the necessity for buffer handling and flush semantics at call sites. And reduces overhead when callers previously had to submit one sample value per API call when only single value submission existed. --- diff --git a/src/input/feed_queue.c b/src/input/feed_queue.c index 4e01313d..d62f3f6b 100644 --- a/src/input/feed_queue.c +++ b/src/input/feed_queue.c @@ -79,6 +79,35 @@ SR_API int feed_queue_logic_submit_one(struct feed_queue_logic *q, return SR_OK; } +SR_API int feed_queue_logic_submit_many(struct feed_queue_logic *q, + const uint8_t *data, size_t samples_count) +{ + uint8_t *wrptr; + size_t space, copy_count; + int ret; + + wrptr = &q->data_bytes[q->fill_count * q->unit_size]; + while (samples_count) { + space = q->alloc_count - q->fill_count; + copy_count = samples_count; + if (copy_count > space) + copy_count = space; + memcpy(wrptr, data, copy_count * q->unit_size); + data += copy_count * q->unit_size; + samples_count -= copy_count; + wrptr += copy_count * q->unit_size; + q->fill_count += copy_count; + if (q->fill_count == q->alloc_count) { + ret = feed_queue_logic_flush(q); + if (ret != SR_OK) + return ret; + wrptr = &q->data_bytes[0]; + } + } + + return SR_OK; +} + SR_API int feed_queue_logic_flush(struct feed_queue_logic *q) { int ret; diff --git a/src/libsigrok-internal.h b/src/libsigrok-internal.h index 7a67911d..68a45f27 100644 --- a/src/libsigrok-internal.h +++ b/src/libsigrok-internal.h @@ -2856,6 +2856,8 @@ SR_API struct feed_queue_logic *feed_queue_logic_alloc( size_t sample_count, size_t unit_size); SR_API int feed_queue_logic_submit_one(struct feed_queue_logic *q, const uint8_t *data, size_t repeat_count); +SR_API int feed_queue_logic_submit_many(struct feed_queue_logic *q, + const uint8_t *data, size_t samples_count); SR_API int feed_queue_logic_flush(struct feed_queue_logic *q); SR_API int feed_queue_logic_send_trigger(struct feed_queue_logic *q); SR_API void feed_queue_logic_free(struct feed_queue_logic *q);