Skip to content

Commit

Permalink
Update example to use full API instead of directly checkign full flag
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipjohnston committed Mar 1, 2021
1 parent b9ab8b5 commit b567e5b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions examples/c/circular_buffer/circular_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static void advance_pointer(cbuf_handle_t cbuf)
{
assert(cbuf);

if(cbuf->full)
if(circular_buf_full(cbuf))
{
cbuf->tail = (cbuf->tail + 1) % cbuf->max;
}
Expand Down Expand Up @@ -78,7 +78,7 @@ size_t circular_buf_size(cbuf_handle_t cbuf)

size_t size = cbuf->max;

if(!cbuf->full)
if(!circular_buf_full(cbuf))
{
if(cbuf->head >= cbuf->tail)
{
Expand Down Expand Up @@ -147,7 +147,7 @@ bool circular_buf_empty(cbuf_handle_t cbuf)
{
assert(cbuf);

return (!cbuf->full && (cbuf->head == cbuf->tail));
return (!circular_buf_full(cbuf) && (cbuf->head == cbuf->tail));
}

bool circular_buf_full(cbuf_handle_t cbuf)
Expand Down
6 changes: 3 additions & 3 deletions examples/c/circular_buffer/circular_buffer_no_modulo.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static void advance_pointer(cbuf_handle_t cbuf)
{
assert(cbuf);

if(cbuf->full)
if(circular_buf_full(cbuf))
{
if(++(cbuf->tail) == cbuf->max)
{
Expand Down Expand Up @@ -87,7 +87,7 @@ size_t circular_buf_size(cbuf_handle_t cbuf)

size_t size = cbuf->max;

if(!cbuf->full)
if(!circular_buf_full(cbuf))
{
if(cbuf->head >= cbuf->tail)
{
Expand Down Expand Up @@ -156,7 +156,7 @@ bool circular_buf_empty(cbuf_handle_t cbuf)
{
assert(cbuf);

return (!cbuf->full && (cbuf->head == cbuf->tail));
return (!circular_buf_full(cbuf) && (cbuf->head == cbuf->tail));
}

bool circular_buf_full(cbuf_handle_t cbuf)
Expand Down

0 comments on commit b567e5b

Please sign in to comment.