Files
magenta/include/kernel/ringbuf.h
T

46 lines
1.2 KiB
C
Raw Normal View History

2026-06-06 17:50:23 +01:00
#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