util/queue: rename queue to queue_Queue
This commit is contained in:
parent
c4b4dbeb18
commit
97e834b8af
@ -13,8 +13,8 @@
|
||||
bool pic_ps2_HasMouse;
|
||||
bool pic_ps2_Mouse4Bytes; // the mouse has 4-byte data packages instead of 3
|
||||
|
||||
queue pic_ps2_QueueKeyboard, pic_ps2_QueueMouse;
|
||||
uint8_t __pic_ps2_QueueBufferK[PIC_PS2_QUEUESIZE_KEYBOARD], __pic_ps2_QueueBufferM[PIC_PS2_QUEUESIZE_MOUSE];
|
||||
queue_Queue pic_ps2_QueueKeyboard, pic_ps2_QueueMouse;
|
||||
uint8_t __pic_ps2_QueueBufferK[PIC_PS2_QUEUESIZE_KEYBOARD], __pic_ps2_QueueBufferM[PIC_PS2_QUEUESIZE_MOUSE];
|
||||
|
||||
void pic_ps2_Init() {
|
||||
assert(irq_pic_Enabled && "pic_ps2_Init() requires PIC to be enabled");
|
||||
|
@ -59,7 +59,7 @@ extern bool pic_ps2_Mouse4Bytes; // the mouse has 4-byte data packages instead o
|
||||
#define PIC_PS2_QUEUESIZE_MOUSE 256
|
||||
|
||||
// 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
|
||||
|
18
util/queue.c
18
util/queue.c
@ -3,13 +3,13 @@
|
||||
#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->size = size;
|
||||
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
|
||||
io_Printf("queue_PushByte: full[%llu bytes], discarding byte 0x%x\n", q->size, b);
|
||||
return;
|
||||
@ -21,7 +21,7 @@ void queue_PushByte(queue *q, const uint8_t b) {
|
||||
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) {
|
||||
io_WriteConsoleASCII("queue_PopByte: poping an empty queue\n");
|
||||
return 0;
|
||||
@ -34,7 +34,7 @@ uint8_t queue_PopByte(queue *q) {
|
||||
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
|
||||
if (queue_Space(q) < size)
|
||||
return;
|
||||
@ -42,7 +42,7 @@ void queue_Push(queue *q, const void *buffer, uintptr_t size) {
|
||||
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)
|
||||
return 0;
|
||||
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;
|
||||
}
|
||||
|
||||
uint8_t queue_FrontByte(queue *q) {
|
||||
uint8_t queue_FrontByte(queue_Queue *q) {
|
||||
if (q->count == 0) {
|
||||
io_WriteConsoleASCII("queue_TopByte: accessing an empty queue\n");
|
||||
return 0;
|
||||
@ -58,14 +58,14 @@ uint8_t queue_FrontByte(queue *q) {
|
||||
return *((uint8_t *)q->begin);
|
||||
}
|
||||
|
||||
bool queue_Empty(queue *q) {
|
||||
bool queue_Empty(queue_Queue *q) {
|
||||
return q->count == 0;
|
||||
}
|
||||
|
||||
uintptr_t queue_Size(queue *q) {
|
||||
uintptr_t queue_Size(queue_Queue *q) {
|
||||
return q->count;
|
||||
}
|
||||
|
||||
uintptr_t queue_Space(queue *q) {
|
||||
uintptr_t queue_Space(queue_Queue *q) {
|
||||
return q->size - q->count;
|
||||
}
|
||||
|
20
util/queue.h
20
util/queue.h
@ -13,35 +13,35 @@ typedef struct {
|
||||
uintptr_t size; // size of data buffer
|
||||
void * begin, *end; // begin and past-the-end for in-queue data
|
||||
uintptr_t count; // number of in-queue bytes
|
||||
} queue;
|
||||
} queue_Queue;
|
||||
|
||||
// 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
|
||||
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
|
||||
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
|
||||
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
|
||||
// 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
|
||||
uint8_t queue_FrontByte(queue *q);
|
||||
uint8_t queue_FrontByte(queue_Queue *q);
|
||||
|
||||
// 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
|
||||
uintptr_t queue_Size(queue *q);
|
||||
uintptr_t queue_Size(queue_Queue *q);
|
||||
|
||||
// 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
|
||||
|
Loading…
Reference in New Issue
Block a user