diff --git a/examples/c/circular_buffer/circular_buffer.h b/examples/c/circular_buffer/circular_buffer.h index 1584331..9d8ed1a 100644 --- a/examples/c/circular_buffer/circular_buffer.h +++ b/examples/c/circular_buffer/circular_buffer.h @@ -10,7 +10,8 @@ typedef struct circular_buf_t circular_buf_t; typedef circular_buf_t* cbuf_handle_t; /// Pass in a storage buffer and size, returns a circular buffer handle -/// Requires: buffer is not NULL, size > 0 +/// Requires: buffer is not NULL, size > 0 (size > 1 for the threadsafe +// version, because it holds size - 1 elements) /// Ensures: cbuf has been created and is returned in an empty state cbuf_handle_t circular_buf_init(uint8_t* buffer, size_t size); diff --git a/examples/c/circular_buffer/circular_buffer_no_modulo_threadsafe.c b/examples/c/circular_buffer/circular_buffer_no_modulo_threadsafe.c index 484662a..2049939 100644 --- a/examples/c/circular_buffer/circular_buffer_no_modulo_threadsafe.c +++ b/examples/c/circular_buffer/circular_buffer_no_modulo_threadsafe.c @@ -47,7 +47,7 @@ static void retreat_pointer(cbuf_handle_t cbuf) cbuf_handle_t circular_buf_init(uint8_t* buffer, size_t size) { - assert(buffer && size); + assert(buffer && size > 1); cbuf_handle_t cbuf = malloc(sizeof(circular_buf_t)); assert(cbuf); @@ -150,7 +150,7 @@ bool circular_buf_empty(cbuf_handle_t cbuf) { assert(cbuf); - return (!circular_buf_full(cbuf) && (cbuf->head == cbuf->tail)); + return cbuf->head == cbuf->tail; } bool circular_buf_full(circular_buf_t* cbuf)