From 5f0a15d4dcd2993305ff102fc57829f1a7eb7893 Mon Sep 17 00:00:00 2001 From: Russell Gallop Date: Thu, 11 Aug 2011 16:06:04 +0100 Subject: [PATCH] Convert to use unsigned buffer --- module_usb_midi/src/queue.c | 15 +++++++-------- module_usb_midi/src/queue.h | 8 ++++---- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/module_usb_midi/src/queue.c b/module_usb_midi/src/queue.c index 90602c33..3d52a06e 100644 --- a/module_usb_midi/src/queue.c +++ b/module_usb_midi/src/queue.c @@ -2,21 +2,21 @@ #include "queue.h" // This presumes that the xc compiler will not re-use the mem passed to init_queue -void init_queue(queue *q, int arr[], int size) { +void init_queue(queue *q, unsigned arr[], int size) { q->rdptr = 0; q->wrptr = 0; - q->data = (intptr_t)arr; + q->data = (uintptr_t)arr; q->size = size; // presume that size is power of two q->mask = size - 1; } -extern inline void enqueue(queue *q, int value) { - ((int *)q->data)[q->wrptr & q->mask] = value; +extern inline void enqueue(queue *q, unsigned value) { + ((unsigned *)q->data)[q->wrptr & q->mask] = value; q->wrptr++; } -extern inline int dequeue(queue *q) { - int retval = ((int *)q->data)[q->rdptr & q->mask]; +extern inline unsigned dequeue(queue *q) { + unsigned retval = ((unsigned *)q->data)[q->rdptr & q->mask]; q->rdptr++; return retval; } @@ -41,8 +41,7 @@ extern inline int space(queue *q) { void dump(queue *q) { for (int i = q->rdptr; i != q->wrptr; i++) { - printf("a[%d] = %d\n", i & q->mask, ((int *)q->data)[i & q->mask]); + printf("a[%d] = %d\n", i & q->mask, ((unsigned *)q->data)[i & q->mask]); } } - diff --git a/module_usb_midi/src/queue.h b/module_usb_midi/src/queue.h index 1e560ecf..615cac67 100644 --- a/module_usb_midi/src/queue.h +++ b/module_usb_midi/src/queue.h @@ -5,16 +5,16 @@ #include typedef struct queue { - intptr_t data; + uintptr_t data; int rdptr; // Using absolute indices which count reads and writes so this needs to be considered when accessing. int wrptr; int size; int mask; } queue; -void init_queue(REFERENCE_PARAM(queue, q), int arr[], int size); -void enqueue(REFERENCE_PARAM(queue, q), int value); -int dequeue(REFERENCE_PARAM(queue, q)); +void init_queue(REFERENCE_PARAM(queue, q), unsigned arr[], int size); +void enqueue(REFERENCE_PARAM(queue, q), unsigned value); +unsigned dequeue(REFERENCE_PARAM(queue, q)); int isempty(REFERENCE_PARAM(queue, q)); int isfull(REFERENCE_PARAM(queue, q)); int items(REFERENCE_PARAM(queue, q));