]> sigrok.org Git - libsigrok.git/commitdiff
feed_queue: add API to submit multiple sample values at once
authorGerhard Sittig <redacted>
Sun, 15 Oct 2023 08:22:20 +0000 (10:22 +0200)
committerGerhard Sittig <redacted>
Mon, 16 Oct 2023 20:19:28 +0000 (22:19 +0200)
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.

src/input/feed_queue.c
src/libsigrok-internal.h

index 4e01313dec0a33e26ddcf1b829656af56ce7e84f..d62f3f6b71fb000e4018135441920bc502891e33 100644 (file)
@@ -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;
index 7a67911dcc6240bd52443dfa9597f7c5c708a922..68a45f27766160ebc092d561e678a39eabbf0547 100644 (file)
@@ -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);