starting to work on pty drivers, fork(), and scheduler redesign

This commit is contained in:
2026-07-07 00:13:24 -05:00
parent 6d7a23d747
commit 177a0b8fe9
29 changed files with 859 additions and 111 deletions

34
kernel/lib/ringbuf.c Normal file
View File

@@ -0,0 +1,34 @@
#include <lib/ringbuf.h>
void ring_buf_init(ring_buf_t* rb) {
rb->head = 0;
rb->tail = 0;
}
int ring_buf_is_empty(ring_buf_t* rb) {
return rb->head == rb->tail;
}
int ring_buf_is_full(ring_buf_t* rb) {
return ((rb->head + 1) % PTY_BUFFER_SIZE) == rb->tail;
}
int ring_buf_write(ring_buf_t *buf, char c) {
if (ring_buf_is_full(buf)) {
return -1;
}
buf->data[buf->head] = c;
buf->head = (buf->head + 1) % PTY_BUFFER_SIZE;
return 0;
}
int ring_buf_read(ring_buf_t *buf, char *c) {
if (ring_buf_is_empty(buf)) {
return -1;
}
*c = buf->data[buf->tail];
buf->tail = (buf->tail + 1) % PTY_BUFFER_SIZE;
return 0;
}

20
kernel/lib/ringbuf.h Normal file
View File

@@ -0,0 +1,20 @@
#ifndef KRINGBUF_H
#define KRINGBUF_H
#include <stddef.h>
#define PTY_BUFFER_SIZE 1024
typedef struct {
char data[PTY_BUFFER_SIZE];
size_t head;
size_t tail;
} ring_buf_t;
void ring_buf_init(ring_buf_t* rb);
int ring_buf_is_empty(ring_buf_t* rb);
int ring_buf_is_full(ring_buf_t* rb);
int ring_buf_write(ring_buf_t *buf, char c);
int ring_buf_read(ring_buf_t *buf, char *c);
#endif