forked from PAWPAW-Mirror/lib_xua
Convert to use unsigned buffer
This commit is contained in:
@@ -2,21 +2,21 @@
|
|||||||
#include "queue.h"
|
#include "queue.h"
|
||||||
|
|
||||||
// This presumes that the xc compiler will not re-use the mem passed to init_queue
|
// 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->rdptr = 0;
|
||||||
q->wrptr = 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->size = size; // presume that size is power of two
|
||||||
q->mask = size - 1;
|
q->mask = size - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern inline void enqueue(queue *q, int value) {
|
extern inline void enqueue(queue *q, unsigned value) {
|
||||||
((int *)q->data)[q->wrptr & q->mask] = value;
|
((unsigned *)q->data)[q->wrptr & q->mask] = value;
|
||||||
q->wrptr++;
|
q->wrptr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern inline int dequeue(queue *q) {
|
extern inline unsigned dequeue(queue *q) {
|
||||||
int retval = ((int *)q->data)[q->rdptr & q->mask];
|
unsigned retval = ((unsigned *)q->data)[q->rdptr & q->mask];
|
||||||
q->rdptr++;
|
q->rdptr++;
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
@@ -41,8 +41,7 @@ extern inline int space(queue *q) {
|
|||||||
|
|
||||||
void dump(queue *q) {
|
void dump(queue *q) {
|
||||||
for (int i = q->rdptr; i != q->wrptr; i++) {
|
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]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,16 +5,16 @@
|
|||||||
#include <xccompat.h>
|
#include <xccompat.h>
|
||||||
|
|
||||||
typedef struct queue {
|
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 rdptr; // Using absolute indices which count reads and writes so this needs to be considered when accessing.
|
||||||
int wrptr;
|
int wrptr;
|
||||||
int size;
|
int size;
|
||||||
int mask;
|
int mask;
|
||||||
} queue;
|
} queue;
|
||||||
|
|
||||||
void init_queue(REFERENCE_PARAM(queue, q), int arr[], int size);
|
void init_queue(REFERENCE_PARAM(queue, q), unsigned arr[], int size);
|
||||||
void enqueue(REFERENCE_PARAM(queue, q), int value);
|
void enqueue(REFERENCE_PARAM(queue, q), unsigned value);
|
||||||
int dequeue(REFERENCE_PARAM(queue, q));
|
unsigned dequeue(REFERENCE_PARAM(queue, q));
|
||||||
int isempty(REFERENCE_PARAM(queue, q));
|
int isempty(REFERENCE_PARAM(queue, q));
|
||||||
int isfull(REFERENCE_PARAM(queue, q));
|
int isfull(REFERENCE_PARAM(queue, q));
|
||||||
int items(REFERENCE_PARAM(queue, q));
|
int items(REFERENCE_PARAM(queue, q));
|
||||||
|
|||||||
Reference in New Issue
Block a user