summaryrefslogtreecommitdiff
path: root/toxcore/util.c
diff options
context:
space:
mode:
authorEniz Vukovic <eniz_vukovic@hotmail.com>2015-10-10 23:54:23 +0200
committerEniz Vukovic <eniz_vukovic@hotmail.com>2015-10-10 23:54:23 +0200
commitd6fdf16520b6f242935ca95eeb739ec9a8eaa14c (patch)
tree069f3355835aa0497fe494c36554ea24d0b222f1 /toxcore/util.c
parentbf5e9b89d2a67c293aae503c03e193307ea7990b (diff)
New Adaptive BR algorithm, cleanups and fixes
Diffstat (limited to 'toxcore/util.c')
-rw-r--r--toxcore/util.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/toxcore/util.c b/toxcore/util.c
index 5865a172..81fa84c6 100644
--- a/toxcore/util.c
+++ b/toxcore/util.c
@@ -234,14 +234,6 @@ bool rb_read(RingBuffer *b, void **p)
234 b->start = (b->start + 1) % b->size; 234 b->start = (b->start + 1) % b->size;
235 return true; 235 return true;
236} 236}
237void rb_clear(RingBuffer *b)
238{
239 while (!rb_empty(b)) {
240 void *p;
241 rb_read(b, &p);
242 free(p);
243 }
244}
245RingBuffer *rb_new(int size) 237RingBuffer *rb_new(int size)
246{ 238{
247 RingBuffer *buf = calloc(sizeof(RingBuffer), 1); 239 RingBuffer *buf = calloc(sizeof(RingBuffer), 1);
@@ -257,11 +249,28 @@ RingBuffer *rb_new(int size)
257 249
258 return buf; 250 return buf;
259} 251}
260void rb_free(RingBuffer *b) 252void rb_kill(RingBuffer *b)
261{ 253{
262 if (b) { 254 if (b) {
263 rb_clear(b);
264 free(b->data); 255 free(b->data);
265 free(b); 256 free(b);
266 } 257 }
267} 258}
259uint16_t rb_size(const RingBuffer* b)
260{
261 if (rb_empty(b))
262 return 0;
263
264 return
265 b->end > b->start ?
266 b->end - b->start :
267 (b->size - b->start) + b->end;
268}
269uint16_t rb_data(const RingBuffer* b, void** dest)
270{
271 uint16_t i = 0;
272 for (; i < rb_size(b); i++)
273 dest[i] = b->data[(b->start + i) % b->size];
274
275 return i;
276}