53 lines
1.8 KiB
C
53 lines
1.8 KiB
C
#ifndef BLUELIB_CORE_RINGBUFFER_H_
|
|
#define BLUELIB_CORE_RINGBUFFER_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;
|
|
|
|
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;
|
|
|
|
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_read(
|
|
b_ringbuffer *buf, void *p, size_t count, size_t *nr_read);
|
|
BLUE_API b_status b_ringbuffer_write(
|
|
b_ringbuffer *buf, const void *p, size_t count, size_t *nr_written);
|
|
|
|
BLUE_API int b_ringbuffer_getc(b_ringbuffer *buf);
|
|
BLUE_API b_status b_ringbuffer_putc(b_ringbuffer *buf, int c);
|
|
|
|
BLUE_API size_t b_ringbuffer_write_capacity_remaining(const b_ringbuffer *buf);
|
|
BLUE_API size_t b_ringbuffer_available_data_remaining(const b_ringbuffer *buf);
|
|
|
|
BLUE_API b_status b_ringbuffer_open_read_buffer(
|
|
b_ringbuffer *buf, const void **ptr, size_t *length);
|
|
BLUE_API b_status b_ringbuffer_close_read_buffer(
|
|
b_ringbuffer *buf, const void **ptr, size_t nr_read);
|
|
|
|
BLUE_API b_status b_ringbuffer_open_write_buffer(
|
|
b_ringbuffer *buf, void **ptr, size_t *capacity);
|
|
BLUE_API b_status b_ringbuffer_close_write_buffer(
|
|
b_ringbuffer *buf, void **ptr, size_t nr_written);
|
|
|
|
#endif
|