allow pop without dest

master
Ondřej Hruška 2 years ago
parent 73e0d601db
commit 3d96951ce3
  1. 9
      circbuf_deque/circbuf.c

@ -107,14 +107,17 @@ bool cbuf_push(CircBuf *cb, const void *source)
/** Pop one element from the front_writepos */ /** Pop one element from the front_writepos */
bool cbuf_pop(CircBuf *cb, void *dest) bool cbuf_pop(CircBuf *cb, void *dest)
{ {
if (cb == NULL || dest == NULL || cb->num_used == 0) { if (cb == NULL || cb->num_used == 0) {
return false; return false;
} }
cb->num_used--; cb->num_used--;
circbuf_size_t f = front_writepos(cb); circbuf_size_t f = front_writepos(cb);
if (dest != NULL) {
read_buffer(cb, f, dest); read_buffer(cb, f, dest);
}
#ifdef CIRCBUF_ZERO_FREE_SLOTS #ifdef CIRCBUF_ZERO_FREE_SLOTS
memset(PV_OFFS(cb->buf, cb->elem_size, f), 0, cb->elem_size); memset(PV_OFFS(cb->buf, cb->elem_size, f), 0, cb->elem_size);
@ -196,11 +199,13 @@ bool cbuf_push_back(CircBuf *cb, const void *source)
/** Pop one element from the back */ /** Pop one element from the back */
bool cbuf_pop_back(CircBuf *cb, void *dest) bool cbuf_pop_back(CircBuf *cb, void *dest)
{ {
if (cb == NULL || dest == NULL || cb->num_used == 0) { if (cb == NULL || cb->num_used == 0) {
return false; return false;
} }
if (dest != NULL) {
read_buffer(cb, cb->back, dest); read_buffer(cb, cb->back, dest);
}
#ifdef CIRCBUF_ZERO_FREE_SLOTS #ifdef CIRCBUF_ZERO_FREE_SLOTS
memset(PV_OFFS(cb->buf, cb->elem_size, cb->back), 0, cb->elem_size); memset(PV_OFFS(cb->buf, cb->elem_size, cb->back), 0, cb->elem_size);

Loading…
Cancel
Save