diff --git a/app/src/util/cbuf.h b/app/src/util/cbuf.h index 01e41044..c1e4bb8d 100644 --- a/app/src/util/cbuf.h +++ b/app/src/util/cbuf.h @@ -2,11 +2,6 @@ #ifndef CBUF_H #define CBUF_H -#include "common.h" - -#include -#include - // To define a circular buffer type of 20 ints: // struct cbuf_int CBUF(int, 20); // @@ -29,24 +24,26 @@ #define cbuf_init(PCBUF) \ (void) ((PCBUF)->head = (PCBUF)->tail = 0) -#define cbuf_push(PCBUF, ITEM) \ - ({ \ - bool ok = !cbuf_is_full(PCBUF); \ - if (ok) { \ - (PCBUF)->data[(PCBUF)->head] = (ITEM); \ - (PCBUF)->head = ((PCBUF)->head + 1) % cbuf_size_(PCBUF); \ - } \ - ok; \ - }) +#define cbuf_push(PCBUF, ITEM) \ + ( \ + (!cbuf_is_full(PCBUF)) \ + ? ( \ + (PCBUF)->data[(PCBUF)->head] = (ITEM), \ + (PCBUF)->head = ((PCBUF)->head + 1) % cbuf_size_(PCBUF), \ + 1 \ + ) \ + : 0 \ + ) -#define cbuf_take(PCBUF, PITEM) \ - ({ \ - bool ok = !cbuf_is_empty(PCBUF); \ - if (ok) { \ - *(PITEM) = (PCBUF)->data[(PCBUF)->tail]; \ - (PCBUF)->tail = ((PCBUF)->tail + 1) % cbuf_size_(PCBUF); \ - } \ - ok; \ - }) +#define cbuf_take(PCBUF, PITEM) \ + ( \ + (!cbuf_is_empty(PCBUF)) \ + ? ( \ + *(PITEM) = (PCBUF)->data[(PCBUF)->tail], \ + (PCBUF)->tail = ((PCBUF)->tail + 1) % cbuf_size_(PCBUF), \ + 1 \ + ) \ + : 0 \ + ) #endif diff --git a/app/src/util/queue.h b/app/src/util/queue.h index 0681070c..8644e230 100644 --- a/app/src/util/queue.h +++ b/app/src/util/queue.h @@ -2,8 +2,6 @@ #ifndef QUEUE_H #define QUEUE_H -#include "common.h" - #include #include #include @@ -50,28 +48,29 @@ // // push a new item into the queue -#define queue_push(PQ, NEXTFIELD, ITEM) \ - (void) ({ \ - (ITEM)->NEXTFIELD = NULL; \ - if (queue_is_empty(PQ)) { \ - (PQ)->first = (PQ)->last = (ITEM); \ - } else { \ - (PQ)->last->NEXTFIELD = (ITEM); \ - (PQ)->last = (ITEM); \ - } \ - }) +#define queue_push(PQ, NEXTFIELD, ITEM) \ + (void) ( \ + (ITEM)->NEXTFIELD = NULL, \ + (queue_is_empty(PQ)) \ + ? (PQ)->first = (PQ)->last = (ITEM) \ + : ( \ + (PQ)->last->NEXTFIELD = (ITEM), \ + (PQ)->last = (ITEM) \ + ) \ + \ + ) // take the next item and remove it from the queue (the queue must not be empty) // the result is stored in *(PITEM) // (without typeof(), we could not store a local variable having the correct // type so that we can "return" it) -#define queue_take(PQ, NEXTFIELD, PITEM) \ - (void) ({ \ - assert(!queue_is_empty(PQ)); \ - *(PITEM) = (PQ)->first; \ - (PQ)->first = (PQ)->first->NEXTFIELD; \ - }) - // no need to update (PQ)->last if the queue is left empty: - // (PQ)->last is undefined if !(PQ)->first anyway +#define queue_take(PQ, NEXTFIELD, PITEM) \ + (void) ( \ + assert(!queue_is_empty(PQ)), \ + *(PITEM) = (PQ)->first, \ + (PQ)->first = (PQ)->first->NEXTFIELD \ + ) +// no need to update (PQ)->last if the queue is left empty: +// (PQ)->last is undefined if !(PQ)->first anyway #endif