diff --git a/driver.c b/driver.c index 58045ed..19d0e74 100644 --- a/driver.c +++ b/driver.c @@ -4,27 +4,16 @@ #include #include -#define rb_size_t size_t +#ifndef DEBUG +#define DEBUG +#endif + +// #define rb_size_t size_t // #define rb_size_t int #include "ringbuf.h" typedef int DATATYPE; -/** - * @brief Debug print and empty the ringbuf - */ -void -rb_debug_empty(struct RingBuf *rb) -{ - int d; - if(rb->count == 0) - return; - printf("Debug Data: ["); - while(rb_pop_front(rb, &d, memcpy) == ReadOk) - printf("%d,", d); - printf("\b]\n"); -} - int main(void) { diff --git a/ringbuf.c b/ringbuf.c index dc2078f..59626f7 100644 --- a/ringbuf.c +++ b/ringbuf.c @@ -131,6 +131,21 @@ rb_pop_front(struct RingBuf *rb, void *item, MEMCPY_T memcpy_fn) return ReadOk; } +#ifdef DEBUG +#include + +void +rb_debug_empty(struct RingBuf *rb) +{ + int d; + if(rb->count == 0) + return; + printf("Debug Data: ["); + while(rb_pop_front(rb, &d, memcpy) == ReadOk) + printf("%d,", d); + printf("\b]\n"); +} + void rb_debug_print(struct RingBuf *rb) { @@ -147,3 +162,5 @@ rb_debug_print(struct RingBuf *rb) DEBUG_PRINT("============%s\n", ""); } + +#endif diff --git a/ringbuf.h b/ringbuf.h index 46db542..1844437 100644 --- a/ringbuf.h +++ b/ringbuf.h @@ -111,12 +111,25 @@ enum ReadResult rb_pop_front(struct RingBuf *rb, void *item, /** * @brief Free the ring buffer + * + * @details This function is idempotent, consecutive calls will not result in a + * double free. + * * @param rb The ring buffer * @param free The free function */ void rb_destroy(struct RingBuf *rb, void(free)()); +#ifdef DEBUG + /** * @brief Debug print */ void rb_debug_print(struct RingBuf *rb); + +/** + * @brief Debug print and empty the ringbuf + */ +void rb_debug_empty(struct RingBuf *rb); + +#endif