util/queue: rename queue to queue_Queue

This commit is contained in:
Edgaru089 2021-11-14 18:19:32 +08:00
parent c4b4dbeb18
commit 97e834b8af
4 changed files with 22 additions and 22 deletions

View File

@ -13,8 +13,8 @@
bool pic_ps2_HasMouse; bool pic_ps2_HasMouse;
bool pic_ps2_Mouse4Bytes; // the mouse has 4-byte data packages instead of 3 bool pic_ps2_Mouse4Bytes; // the mouse has 4-byte data packages instead of 3
queue pic_ps2_QueueKeyboard, pic_ps2_QueueMouse; queue_Queue pic_ps2_QueueKeyboard, pic_ps2_QueueMouse;
uint8_t __pic_ps2_QueueBufferK[PIC_PS2_QUEUESIZE_KEYBOARD], __pic_ps2_QueueBufferM[PIC_PS2_QUEUESIZE_MOUSE]; uint8_t __pic_ps2_QueueBufferK[PIC_PS2_QUEUESIZE_KEYBOARD], __pic_ps2_QueueBufferM[PIC_PS2_QUEUESIZE_MOUSE];
void pic_ps2_Init() { void pic_ps2_Init() {
assert(irq_pic_Enabled && "pic_ps2_Init() requires PIC to be enabled"); assert(irq_pic_Enabled && "pic_ps2_Init() requires PIC to be enabled");

View File

@ -59,7 +59,7 @@ extern bool pic_ps2_Mouse4Bytes; // the mouse has 4-byte data packages instead o
#define PIC_PS2_QUEUESIZE_MOUSE 256 #define PIC_PS2_QUEUESIZE_MOUSE 256
// data queue in bytes for the Keyboard and Mouse IRQs // data queue in bytes for the Keyboard and Mouse IRQs
extern queue pic_ps2_QueueKeyboard, irq_pic_ps2_QueueMouse; extern queue_Queue pic_ps2_QueueKeyboard, irq_pic_ps2_QueueMouse;
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -3,13 +3,13 @@
#include "../runtime/stdio.h" #include "../runtime/stdio.h"
void queue_InitBuffered(queue *q, void *buffer, uintptr_t size) { void queue_InitBuffered(queue_Queue *q, void *buffer, uintptr_t size) {
q->data = q->begin = q->end = buffer; q->data = q->begin = q->end = buffer;
q->size = size; q->size = size;
q->count = 0; q->count = 0;
} }
void queue_PushByte(queue *q, const uint8_t b) { void queue_PushByte(queue_Queue *q, const uint8_t b) {
if (q->count == q->size) { // no more space if (q->count == q->size) { // no more space
io_Printf("queue_PushByte: full[%llu bytes], discarding byte 0x%x\n", q->size, b); io_Printf("queue_PushByte: full[%llu bytes], discarding byte 0x%x\n", q->size, b);
return; return;
@ -21,7 +21,7 @@ void queue_PushByte(queue *q, const uint8_t b) {
q->end = q->data; // out of the buffer: wrap around q->end = q->data; // out of the buffer: wrap around
} }
uint8_t queue_PopByte(queue *q) { uint8_t queue_PopByte(queue_Queue *q) {
if (q->count == 0) { if (q->count == 0) {
io_WriteConsoleASCII("queue_PopByte: poping an empty queue\n"); io_WriteConsoleASCII("queue_PopByte: poping an empty queue\n");
return 0; return 0;
@ -34,7 +34,7 @@ uint8_t queue_PopByte(queue *q) {
return data; return data;
} }
void queue_Push(queue *q, const void *buffer, uintptr_t size) { void queue_Push(queue_Queue *q, const void *buffer, uintptr_t size) {
// TODO Optimize queue_Push and queue_Pop // TODO Optimize queue_Push and queue_Pop
if (queue_Space(q) < size) if (queue_Space(q) < size)
return; return;
@ -42,7 +42,7 @@ void queue_Push(queue *q, const void *buffer, uintptr_t size) {
queue_PushByte(q, *i); queue_PushByte(q, *i);
} }
uintptr_t queue_Pop(queue *q, void *buffer, uintptr_t size) { uintptr_t queue_Pop(queue_Queue *q, void *buffer, uintptr_t size) {
if (queue_Size(q) < size) if (queue_Size(q) < size)
return 0; return 0;
for (uint8_t *i = buffer; i < (uint8_t *)buffer + size; i++) for (uint8_t *i = buffer; i < (uint8_t *)buffer + size; i++)
@ -50,7 +50,7 @@ uintptr_t queue_Pop(queue *q, void *buffer, uintptr_t size) {
return size; return size;
} }
uint8_t queue_FrontByte(queue *q) { uint8_t queue_FrontByte(queue_Queue *q) {
if (q->count == 0) { if (q->count == 0) {
io_WriteConsoleASCII("queue_TopByte: accessing an empty queue\n"); io_WriteConsoleASCII("queue_TopByte: accessing an empty queue\n");
return 0; return 0;
@ -58,14 +58,14 @@ uint8_t queue_FrontByte(queue *q) {
return *((uint8_t *)q->begin); return *((uint8_t *)q->begin);
} }
bool queue_Empty(queue *q) { bool queue_Empty(queue_Queue *q) {
return q->count == 0; return q->count == 0;
} }
uintptr_t queue_Size(queue *q) { uintptr_t queue_Size(queue_Queue *q) {
return q->count; return q->count;
} }
uintptr_t queue_Space(queue *q) { uintptr_t queue_Space(queue_Queue *q) {
return q->size - q->count; return q->size - q->count;
} }

View File

@ -13,35 +13,35 @@ typedef struct {
uintptr_t size; // size of data buffer uintptr_t size; // size of data buffer
void * begin, *end; // begin and past-the-end for in-queue data void * begin, *end; // begin and past-the-end for in-queue data
uintptr_t count; // number of in-queue bytes uintptr_t count; // number of in-queue bytes
} queue; } queue_Queue;
// initialize a queue with a existing buffer // initialize a queue with a existing buffer
void queue_InitBuffered(queue *q, void *buffer, uintptr_t size); void queue_InitBuffered(queue_Queue *q, void *buffer, uintptr_t size);
// writes one byte to the queue, discarding if full // writes one byte to the queue, discarding if full
void queue_PushByte(queue *q, const uint8_t b); void queue_PushByte(queue_Queue *q, const uint8_t b);
// pops one byte from the front of the queue, returning it // pops one byte from the front of the queue, returning it
uint8_t queue_PopByte(queue *q); uint8_t queue_PopByte(queue_Queue *q);
// write Size bytes to the queue, none written if there is not space for all the bytes // write Size bytes to the queue, none written if there is not space for all the bytes
void queue_Push(queue *q, const void *buffer, uintptr_t size); void queue_Push(queue_Queue *q, const void *buffer, uintptr_t size);
// pops Size bytes from the queue, none popped if there are no enough data // pops Size bytes from the queue, none popped if there are no enough data
// returns the number of bytes popped (either Size or 0) // returns the number of bytes popped (either Size or 0)
uintptr_t queue_Pop(queue *q, void *buffer, uintptr_t size); uintptr_t queue_Pop(queue_Queue *q, void *buffer, uintptr_t size);
// return the byte at the front of the queue // return the byte at the front of the queue
uint8_t queue_FrontByte(queue *q); uint8_t queue_FrontByte(queue_Queue *q);
// tells if the queue is empty // tells if the queue is empty
bool queue_Empty(queue *q); bool queue_Empty(queue_Queue *q);
// returns the number of bytes in the queue // returns the number of bytes in the queue
uintptr_t queue_Size(queue *q); uintptr_t queue_Size(queue_Queue *q);
// returns the empty space left at the end of the queue // returns the empty space left at the end of the queue
uintptr_t queue_Space(queue *q); uintptr_t queue_Space(queue_Queue *q);
#ifdef __cplusplus #ifdef __cplusplus