core: ringbuffer: update from simple struct to a b_object type

This commit is contained in:
2025-10-28 15:14:09 +00:00
parent 5f2bbc7151
commit 2687477cb2
2 changed files with 312 additions and 239 deletions

View File

@@ -1,32 +1,25 @@
#ifndef BLUELIB_CORE_RINGBUFFER_H_
#define BLUELIB_CORE_RINGBUFFER_H_
#ifndef BLUE_CORE_RINGBUFFER_H_
#define BLUE_CORE_RINGBUFFER_H_
#include <blue/core/macros.h>
#include <blue/core/misc.h>
#include <blue/core/status.h>
typedef enum b_ringbuffer_flags {
B_RINGBUFFER_SELF_MALLOC = 0x01u,
B_RINGBUFFER_BUFFER_MALLOC = 0x02u,
B_RINGBUFFER_READ_LOCKED = 0x04u,
B_RINGBUFFER_WRITE_LOCKED = 0x08u,
} b_ringbuffer_flags;
B_DECLS_BEGIN;
typedef struct b_ringbuffer {
b_ringbuffer_flags r_flags;
void *r_buf, *r_opened_buf;
unsigned long r_capacity, r_opened_capacity;
unsigned long r_write_ptr, r_read_ptr;
} b_ringbuffer;
#define B_TYPE_RINGBUFFER (b_ringbuffer_get_type())
B_DECLARE_TYPE(b_ringbuffer);
B_TYPE_CLASS_DECLARATION_BEGIN(b_ringbuffer)
B_TYPE_CLASS_DECLARATION_END(b_ringbuffer)
BLUE_API b_type b_ringbuffer_get_type(void);
BLUE_API b_ringbuffer *b_ringbuffer_create(size_t capacity);
BLUE_API b_ringbuffer *b_ringbuffer_create_with_buffer(void *ptr, size_t capacity);
BLUE_API b_status b_ringbuffer_init(b_ringbuffer *buf, size_t capacity);
BLUE_API b_status b_ringbuffer_init_with_buffer(
b_ringbuffer *buf, void *ptr, size_t capacity);
BLUE_API b_status b_ringbuffer_reset(b_ringbuffer *buf);
BLUE_API b_status b_ringbuffer_destroy(b_ringbuffer *buf);
BLUE_API b_status b_ringbuffer_clear(b_ringbuffer *buf);
BLUE_API b_status b_ringbuffer_read(
b_ringbuffer *buf, void *p, size_t count, size_t *nr_read);
@@ -49,4 +42,6 @@ BLUE_API b_status b_ringbuffer_open_write_buffer(
BLUE_API b_status b_ringbuffer_close_write_buffer(
b_ringbuffer *buf, void **ptr, size_t nr_written);
B_DECLS_END;
#endif