blob: 27bc4a2ffbc5d00ef3407a094b7c68b37eee6c8b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
#include <stdlib.h>
#include <stdbool.h>
typedef int64_t ITEM;
struct circ_buf {
ITEM *buf;
int head;
int tail;
};
struct ringbuf_s {
struct circ_buf cb;
size_t size;
};
typedef struct ringbuf_s ringbuf_t;
ringbuf_t* ringbuf_new(size_t count);
void ringbuf_del(ringbuf_t *rb);
int ringbuf_append(ringbuf_t *rb, ITEM item);
int ringbuf_append_with_overwrite(ringbuf_t *rb, ITEM item);
int ringbuf_read(ringbuf_t *rb, ITEM *buf, size_t count);
size_t ringbuf_read_to_end(ringbuf_t *rb, ITEM *buf, size_t count);
bool ringbuf_peek(ringbuf_t *rb, ITEM *item);
size_t ringbuf_capacity(ringbuf_t *rb);
/* ringbuffer tests */
void ringbuf_init_test(void);
void ringbuf_simple_test(void);
void ringbuf_append_test(void);
void ringbuf_append_wrap_test(void);
void ringbuf_append_overwrite_test(void);
void ringbuf_read_test(void);
void ringbuf_read_to_end_test(void);
|