changeset 283:18e292701db4

Change ringbuffer functionality.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 09 Jun 2011 22:29:40 +0300
parents 3dc86d8eb0a9
children dbf07a4eadd7
files th_util.c
diffstat 1 files changed, 7 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/th_util.c	Thu Jun 09 20:48:17 2011 +0300
+++ b/th_util.c	Thu Jun 09 22:29:40 2011 +0300
@@ -425,7 +425,8 @@
     int i;
     
     for (i = 0; i < buf->n; i++)
-        buf->deallocator(buf->data[i]);
+        if (buf->data[i] != NULL)
+            buf->deallocator(buf->data[i]);
     
     th_free(buf->data);
     th_free(buf);
@@ -434,13 +435,11 @@
 
 void th_ringbuf_add(qringbuf_t *buf, void *ptr)
 {
-    if (buf->n < buf->size) {
-        buf->data[buf->n] = ptr;
+    if (buf->n < buf->size)
         buf->n++;
-    } else {
-        th_free(buf->data[0]);
-        memmove(&(buf->data[0]), &(buf->data[1]), buf->size - 1);
-        buf->data[buf->size - 1] = ptr;
-    }
+
+    th_free(buf->data[0]);
+    memmove(&(buf->data[0]), &(buf->data[1]), buf->size - 1);
+    buf->data[buf->size - 1] = ptr;
 }