procgroup capabilities
All checks were successful
Build documentation / build-and-deploy (push) Successful in 1m55s

This commit is contained in:
2026-02-14 20:48:38 +01:00
parent ddfc93d9cd
commit 690e09339e
10 changed files with 81 additions and 6 deletions

20
kernel/libk/ringbuffer.c Normal file
View File

@@ -0,0 +1,20 @@
#include <libk/ringbuffer.h>
#include <libk/std.h>
#include <libk/string.h>
#include <mm/liballoc.h>
bool ringbuffer_init (struct ringbuffer* rb, size_t capacity, size_t type_size) {
void* buf = malloc (capacity * type_size);
if (buf == NULL)
return false;
memset (rb, 0, sizeof (*rb));
rb->capacity = capacity;
rb->buffer = buf;
return true;
}
void ringbuffer_fini (struct ringbuffer* rb) { free (rb->buffer); }

36
kernel/libk/ringbuffer.h Normal file
View File

@@ -0,0 +1,36 @@
#ifndef _KERNEL_LIBK_RINGBUFFER_H
#define _KERNEL_LIBK_RINGBUFFER_H
#include <libk/std.h>
struct ringbuffer {
void* buffer;
size_t tail;
size_t head;
size_t capacity;
size_t count;
bool full;
};
bool ringbuffer_init (struct ringbuffer* rb, size_t capacity, size_t type_size);
void ringbuffer_fini (struct ringbuffer* rb);
#define ringbuffer_pop(type, rb, data) \
do { \
if ((rb)->count != 0) { \
*(data) = ((type*)(rb)->buffer)[(rb)->tail]; \
(rb)->tail = ((rb)->tail + 1) % (rb)->capacity; \
(rb)->count--; \
} \
} while (0)
#define ringbuffer_push(type, rb, data) \
do { \
if ((rb)->count != (rb)->capacity) { \
((type*)(rb)->buffer)[(rb)->head] = (data); \
(rb)->head = ((rb)->head + 1) % (rb)->capacity; \
(rb)->count++; \
} \
} while (0)
#endif // _KERNEL_LIBK_RINGBUFFER_H

View File

@@ -1,9 +1,11 @@
c += libk/string.c \
libk/printf.c \
libk/putchar_.c \
libk/bm.c
libk/bm.c \
libk/ringbuffer.c
o += libk/string.o \
libk/printf.o \
libk/putchar_.o \
libk/bm.o
libk/bm.o \
libk/ringbuffer.o