From 5eb7fb50c7da934c9934e941032a8d759ef809ac Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Wed, 19 Jan 2011 11:43:52 +0100 Subject: [PATCH] [commtech] CSQ use memcpy in dequeue for fairness Paper about CSQ uses memcpy in enqueue and dequeue. Although it is not possible to use memcpy in enqueue because of current API, it is possible to use memcpy in dequeue, hence this commit. --- communication_techniques/src/communication/csq.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/communication_techniques/src/communication/csq.c b/communication_techniques/src/communication/csq.c index 70c49a2..22b9060 100644 --- a/communication_techniques/src/communication/csq.c +++ b/communication_techniques/src/communication/csq.c @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -89,21 +90,16 @@ void *recv_one_data(void) ssize_t recv_some_data(void **buf, size_t count) { - int i, n; + int n; n = 0; // If all slots are empty, spin while (comm->queue[ctrl.head].flag) { // Dequeue a chunk of data items - for (i = 0; i < SUB_SLOTS; i++) - { - /* - * The behaviour of this is not documented but we know - * the values inside buf won't change during this affectation - */ - *buf++ = comm->queue[ctrl.head].chunk[i]; - } + memcpy(buf, (const void *) + comm->queue[ctrl.head].chunk, + SUB_SLOTS * sizeof(*buf)); n += SUB_SLOTS; comm->queue[ctrl.head].flag = 0; ctrl.head = (ctrl.head + 1) % SLOTS;