From abef6da56913f1c55528103e60a50451a39628b1 Mon Sep 17 00:00:00 2001 From: WlodekM Date: Sun, 16 Jun 2024 10:35:45 +0300 Subject: initial commit --- src/Queue.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/Queue.h (limited to 'src/Queue.h') diff --git a/src/Queue.h b/src/Queue.h new file mode 100644 index 0000000..f62c941 --- /dev/null +++ b/src/Queue.h @@ -0,0 +1,22 @@ +#include "Core.h" + +#ifndef CC_QUEUE_H +#define CC_QUEUE_H + +struct Queue { + cc_uint8* entries; /* Buffer holding the bytes of the queue */ + int structSize; /* Size in bytes of the type of structure this queue holds */ + int capacity; /* Max number of elements in the buffer */ + int mask; /* capacity - 1, as capacity is always a power of two */ + int count; /* Number of used elements */ + int head; /* Head index into the buffer */ + int tail; /* Tail index into the buffer */ +}; +void Queue_Init(struct Queue* queue, cc_uint32 structSize); +/* Appends an entry to the end of the queue, resizing if necessary. */ +void Queue_Enqueue(struct Queue* queue, void* item); +/* Retrieves the entry from the front of the queue. */ +void* Queue_Dequeue(struct Queue* queue); +/* Frees the memory of the queue and resets the members to 0. */ +void Queue_Clear(struct Queue* queue); +#endif \ No newline at end of file -- cgit 1.4.1-2-gfad0