Simple IPC with pipes

This commit is contained in:
2025-09-06 11:47:01 +02:00
parent 643d692259
commit cd0e262e56
21 changed files with 312 additions and 17 deletions

37
kernel/rbuf/rbuf.c Normal file
View File

@ -0,0 +1,37 @@
#include <stdint.h>
#include <stddef.h>
#include "rbuf.h"
int32_t rbuf_push(RBuf *rbuf, uint8_t data) {
size_t next;
next = rbuf->head + 1;
if (next >= rbuf->cap) {
next = 0;
}
if (next == rbuf->tail) {
return -1;
}
rbuf->buffer[rbuf->head] = data;
rbuf->head = next;
return 0;
}
int32_t rbuf_pop(RBuf *rbuf, uint8_t *data) {
size_t next;
if (rbuf->head == rbuf->tail) {
return -1;
}
next = rbuf->tail + 1;
if (next >= rbuf->cap) {
next = 0;
}
*data = rbuf->buffer[rbuf->tail];
rbuf->tail = next;
return 0;
}

17
kernel/rbuf/rbuf.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef RBUF_RBUF_H_
#define RBUF_RBUF_H_
#include <stdint.h>
#include <stddef.h>
typedef struct {
uint8_t *buffer;
size_t head;
size_t tail;
size_t cap;
} RBuf;
int32_t rbuf_push(RBuf *rbuf, uint8_t data);
int32_t rbuf_pop(RBuf *rbuf, uint8_t *data);
#endif // RBUF_RBUF_H_