2024-04-25 20:08:24 +00:00
|
|
|
#pragma once
|
2024-05-06 05:52:30 +00:00
|
|
|
#include <stdalign.h>
|
2024-04-25 20:08:24 +00:00
|
|
|
|
2024-04-30 21:41:31 +00:00
|
|
|
#include "fumocommon.h"
|
|
|
|
|
2024-05-07 22:10:15 +00:00
|
|
|
#define RINGBUF_T(RBUF_ITEM_T, RBUF_LEN) \
|
2024-05-02 22:17:37 +00:00
|
|
|
(&(struct RingBufferT) { \
|
2024-05-06 05:52:30 +00:00
|
|
|
.OFFSET = offsetof(struct { \
|
|
|
|
struct RingBufferHead head; \
|
2024-05-07 22:10:15 +00:00
|
|
|
RBUF_ITEM_T item; \
|
2024-05-06 05:52:30 +00:00
|
|
|
}, item), \
|
2024-05-07 22:10:15 +00:00
|
|
|
.SIZE = sizeof(RBUF_ITEM_T), \
|
2024-05-02 22:17:37 +00:00
|
|
|
.LEN = RBUF_LEN \
|
|
|
|
}) \
|
|
|
|
|
2024-04-29 20:01:48 +00:00
|
|
|
#define RINGBUF_HEAD_INIT ((struct RingBufferHead) { 0, 0 })
|
|
|
|
|
2024-05-07 22:10:15 +00:00
|
|
|
|
|
|
|
typedef const struct RingBufferT {
|
|
|
|
usize OFFSET;
|
|
|
|
usize SIZE;
|
|
|
|
usize LEN;
|
|
|
|
} *const RingBufferT;
|
|
|
|
|
|
|
|
struct RingBufferHead {
|
|
|
|
usize len;
|
|
|
|
usize start;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
usize RingBufferEmpty(RingBufferT T, struct RingBufferHead *head);
|
2024-04-29 20:01:48 +00:00
|
|
|
|
|
|
|
void *RingBufferGet(
|
|
|
|
RingBufferT T,
|
|
|
|
struct RingBufferHead *head,
|
2024-05-07 22:10:15 +00:00
|
|
|
usize i
|
2024-04-29 20:01:48 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
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-05-07 22:10:15 +00:00
|
|
|
usize RingBufferOut(
|
2024-04-29 20:01:48 +00:00
|
|
|
RingBufferT T,
|
2024-05-07 22:10:15 +00:00
|
|
|
usize n,
|
2024-04-29 20:01:48 +00:00
|
|
|
void *dest,
|
|
|
|
struct RingBufferHead *src
|
|
|
|
);
|