ds: add a ringbuffer data structure

This commit is contained in:
2026-06-06 17:50:23 +01:00
parent 44bcc8c805
commit 249ac7a8cf
2 changed files with 368 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
#ifndef KERNEL_RINGBUF_H_
#define KERNEL_RINGBUF_H_
#include <kernel/wait.h>
#include <magenta/types.h>
struct ringbuf {
unsigned int buf_read;
unsigned int buf_write;
unsigned int buf_capacity;
unsigned int buf_flags;
unsigned char *buf_ptr;
struct waitqueue buf_read_queue;
struct waitqueue buf_write_queue;
spin_lock_t buf_lock;
unsigned char *buf_opened_ptr;
unsigned int buf_opened_capacity;
};
#define RINGBUF_DECLARE(name, size) \
static unsigned char __buf_##name[size] = {0}; \
static struct ringbuf name = { \
.buf_ptr = __buf_##name, \
.buf_capacity = size, \
}
extern kern_status_t ringbuf_lock(struct ringbuf *buf, unsigned long *flags);
extern kern_status_t ringbuf_unlock(struct ringbuf *buf, unsigned long flags);
extern kern_status_t ringbuf_read(
struct ringbuf *buf,
void *out,
size_t count,
size_t *nr_read,
unsigned long *irq_flags);
extern kern_status_t ringbuf_write(
struct ringbuf *buf,
const void *out,
size_t count,
size_t *nr_written,
unsigned long *irq_flags);
#endif