Fumofumotris/source/fumoengine/include/ringbuffer.h

56 lines
1.1 KiB
C
Raw Normal View History

2024-04-25 20:08:24 +00:00
#pragma once
#include <iso646.h>
2024-05-06 05:52:30 +00:00
#include <stdalign.h>
2024-04-25 20:08:24 +00:00
#include <stdbool.h>
#include <stdint.h>
2024-04-30 21:41:31 +00:00
#include "fumocommon.h"
2024-04-25 20:08:24 +00:00
typedef const struct RingBufferT {
2024-04-30 04:43:41 +00:00
size_t OFFSET;
2024-04-25 20:08:24 +00:00
size_t SIZE;
2024-04-30 04:43:41 +00:00
size_t LEN;
2024-04-25 20:08:24 +00:00
} *const RingBufferT;
struct RingBufferHead {
2024-04-30 04:43:41 +00:00
size_t len;
size_t start;
2024-04-25 20:08:24 +00:00
};
2024-05-02 22:17:37 +00:00
#define RINGBUF_T_INIT(RBUF_STRUCT, RBUF_ITEM, RBUF_LEN) \
(&(struct RingBufferT) { \
2024-05-06 05:52:30 +00:00
.OFFSET = offsetof(struct { \
struct RingBufferHead head; \
RBUF_ITEM item; \
}, item), \
2024-05-02 22:17:37 +00:00
.SIZE = sizeof(RBUF_ITEM), \
.LEN = RBUF_LEN \
}) \
2024-04-29 20:01:48 +00:00
#define RINGBUF_HEAD_INIT ((struct RingBufferHead) { 0, 0 })
size_t RingBufferEmpty(RingBufferT T, struct RingBufferHead *head);
void *RingBufferGet(
RingBufferT T,
struct RingBufferHead *head,
size_t i
);
void *RingBufferNext(RingBufferT T, struct RingBufferHead *head);
2024-04-30 04:43:41 +00:00
void RingBufferAdd(RingBufferT T, struct RingBufferHead *dest, void *item);
2024-04-29 20:01:48 +00:00
void RingBufferTransfer(
RingBufferT T,
struct RingBufferHead *dest,
struct RingBufferHead *tmp
);
2024-04-25 20:08:24 +00:00
2024-04-29 20:01:48 +00:00
size_t RingBufferOut(
RingBufferT T,
size_t n,
void *dest,
struct RingBufferHead *src
);