rb_clear initial

This commit is contained in:
Imbus 2024-07-02 05:50:59 +02:00
parent d19917bba7
commit 41f817fd5b
2 changed files with 15 additions and 0 deletions

View file

@ -45,6 +45,14 @@ rb_destroy(struct RingBuf *rb, void(free)())
free(rb->buffer); free(rb->buffer);
} }
void
rb_clear(struct RingBuf *rb)
{
rb->count = 0;
rb->write_head = rb->buffer;
rb->read_head = rb->buffer;
}
enum WriteResult enum WriteResult
rb_push_back(struct RingBuf *rb, const void *item, MEMCPY_T memcpy_fn) rb_push_back(struct RingBuf *rb, const void *item, MEMCPY_T memcpy_fn)
{ {

View file

@ -39,6 +39,13 @@ enum ReadResult { Empty, ReadOk }; /** Result of a read */
void rb_init(struct RingBuf *rb, rb_size_t capacity, ALLOC_T alloc, void rb_init(struct RingBuf *rb, rb_size_t capacity, ALLOC_T alloc,
rb_size_t struct_size); rb_size_t struct_size);
/**
* @brief Clear the ring buffer
* @details This function will reset the read and write heads to the beginning
* of the buffer, and set the count to 0. It will not free the buffer.
* @param rb The ring buffer
*/
void rb_clear(struct RingBuf *rb);
/** /**
* @brief Insert data to the ring buffer * @brief Insert data to the ring buffer