From f60900c4b813abbce213db6de217837645c6590e Mon Sep 17 00:00:00 2001 From: iphydf Date: Thu, 22 Sep 2016 15:20:33 +0100 Subject: Move ring buffer out of toxcore/util into toxav. Toxcore itself doesn't use this data structure. Only toxav does, so now toxav owns the code for it. --- toxcore/util.c | 90 ---------------------------------------------------------- toxcore/util.h | 11 ------- 2 files changed, 101 deletions(-) (limited to 'toxcore') diff --git a/toxcore/util.c b/toxcore/util.c index 93a3d436..25068db6 100644 --- a/toxcore/util.c +++ b/toxcore/util.c @@ -193,93 +193,3 @@ int create_recursive_mutex(pthread_mutex_t *mutex) return 0; } - - -struct RingBuffer { - uint16_t size; /* Max size */ - uint16_t start; - uint16_t end; - void **data; -}; - -bool rb_full(const RingBuffer *b) -{ - return (b->end + 1) % b->size == b->start; -} -bool rb_empty(const RingBuffer *b) -{ - return b->end == b->start; -} -void *rb_write(RingBuffer *b, void *p) -{ - void *rc = NULL; - - if ((b->end + 1) % b->size == b->start) { /* full */ - rc = b->data[b->start]; - } - - b->data[b->end] = p; - b->end = (b->end + 1) % b->size; - - if (b->end == b->start) { - b->start = (b->start + 1) % b->size; - } - - return rc; -} -bool rb_read(RingBuffer *b, void **p) -{ - if (b->end == b->start) { /* Empty */ - *p = NULL; - return false; - } - - *p = b->data[b->start]; - b->start = (b->start + 1) % b->size; - return true; -} -RingBuffer *rb_new(int size) -{ - RingBuffer *buf = (RingBuffer *)calloc(sizeof(RingBuffer), 1); - - if (!buf) { - return NULL; - } - - buf->size = size + 1; /* include empty elem */ - - if (!(buf->data = (void **)calloc(buf->size, sizeof(void *)))) { - free(buf); - return NULL; - } - - return buf; -} -void rb_kill(RingBuffer *b) -{ - if (b) { - free(b->data); - free(b); - } -} -uint16_t rb_size(const RingBuffer *b) -{ - if (rb_empty(b)) { - return 0; - } - - return - b->end > b->start ? - b->end - b->start : - (b->size - b->start) + b->end; -} -uint16_t rb_data(const RingBuffer *b, void **dest) -{ - uint16_t i = 0; - - for (; i < rb_size(b); i++) { - dest[i] = b->data[(b->start + i) % b->size]; - } - - return i; -} diff --git a/toxcore/util.h b/toxcore/util.h index 840f0a3e..20469b75 100644 --- a/toxcore/util.h +++ b/toxcore/util.h @@ -58,15 +58,4 @@ int load_state(load_state_callback_func load_state_callback, void *outer, /* Returns -1 if failed or 0 if success */ int create_recursive_mutex(pthread_mutex_t *mutex); -/* Ring buffer */ -typedef struct RingBuffer RingBuffer; -bool rb_full(const RingBuffer *b); -bool rb_empty(const RingBuffer *b); -void *rb_write(RingBuffer *b, void *p); -bool rb_read(RingBuffer *b, void **p); -RingBuffer *rb_new(int size); -void rb_kill(RingBuffer *b); -uint16_t rb_size(const RingBuffer *b); -uint16_t rb_data(const RingBuffer *b, void **dest); - #endif /* __UTIL_H__ */ -- cgit v1.2.3