diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 16:28:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 16:28:20 +0000 |
commit | dcc721a95bef6f0d8e6d8775b8efe33e5aecd562 (patch) | |
tree | 66a2774cd0ee294d019efd71d2544c70f42b2842 /runtime/perctile_ringbuf.h | |
parent | Initial commit. (diff) | |
download | rsyslog-dcc721a95bef6f0d8e6d8775b8efe33e5aecd562.tar.xz rsyslog-dcc721a95bef6f0d8e6d8775b8efe33e5aecd562.zip |
Adding upstream version 8.2402.0.upstream/8.2402.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'runtime/perctile_ringbuf.h')
-rw-r--r-- | runtime/perctile_ringbuf.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/runtime/perctile_ringbuf.h b/runtime/perctile_ringbuf.h new file mode 100644 index 0000000..27bc4a2 --- /dev/null +++ b/runtime/perctile_ringbuf.h @@ -0,0 +1,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); |