123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
-
-
- #ifndef __RING_BUFFER_H__
- #define __RING_BUFFER_H__
-
- #include <stddef.h>
- #include <stdint.h>
- #include <stdbool.h>
-
- struct ring_buffer {
- void *buffer;
- size_t size;
- size_t el_len;
- size_t head, tail;
- bool full;
- };
- #define RB_INIT(b, s, e) { .buffer = b, .size = s, .el_len = e, .head = 0, .tail = 0, .full = false }
-
- void rb_add(struct ring_buffer *rb, const void *data, size_t length);
- #define rb_push(rb, v) rb_add(rb, v, 1)
- size_t rb_len(struct ring_buffer *rb);
- #define rb_space(rb) ((rb)->size - rb_len(rb))
- void rb_dump(struct ring_buffer *rb, void (*write)(const void *, size_t), size_t skip);
- void rb_move(struct ring_buffer *rb, void (*write)(const void *, size_t));
- void rb_peek(struct ring_buffer *rb, void *buf);
- void rb_pop(struct ring_buffer *rb, void *buf);
- size_t rb_get(struct ring_buffer *rb, void *data, size_t length);
-
- #endif // __RING_BUFFER_H__
|