changeset 158:79e904905dbf

Merged.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 07 Feb 2015 01:39:20 +0200
parents e96c900ca6f1 (diff) 23a79bd6c9d6 (current diff)
children fc914ff7a9b8
files th_util.c
diffstat 2 files changed, 33 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/th_util.c	Sat Feb 07 00:33:41 2015 +0200
+++ b/th_util.c	Sat Feb 07 01:39:20 2015 +0200
@@ -240,6 +240,19 @@
 }
 
 
+void th_llist_free_func_node(th_llist_t *list, void (*freefunc)(th_llist_t *))
+{
+    th_llist_t *curr = list;
+
+    while (curr != NULL)
+    {
+        th_llist_t *next = curr->next;
+        freefunc(curr);
+        curr = next;
+    }
+}
+
+
 void th_llist_free_func(th_llist_t *list, void (*freefunc)(void *data))
 {
     th_llist_t *curr = list;
@@ -247,7 +260,7 @@
     while (curr != NULL)
     {
         th_llist_t *next = curr->next;
-        if (freefunc != NULL && curr->data != NULL)
+        if (curr->data != NULL)
             freefunc(curr->data);
         th_free(curr);
         curr = next;
@@ -257,7 +270,14 @@
 
 void th_llist_free(th_llist_t *list)
 {
-    th_llist_free_func(list, NULL);
+    th_llist_t *curr = list;
+
+    while (curr != NULL)
+    {
+        th_llist_t *next = curr->next;
+        th_free(curr);
+        curr = next;
+    }
 }
 
 
@@ -523,9 +543,9 @@
 /*
  * Ringbuffers
  */
-qringbuf_t * th_ringbuf_new(const size_t size, void (*mdeallocator)(void *data))
+th_ringbuf_t * th_ringbuf_new(const size_t size, void (*mdeallocator)(void *data))
 {
-    qringbuf_t *res = th_malloc0(sizeof(qringbuf_t));
+    th_ringbuf_t *res = th_malloc0(sizeof(th_ringbuf_t));
     
     res->data = (char **) th_calloc(size, sizeof(char *));
     res->size = size;
@@ -536,7 +556,7 @@
 }
 
 
-BOOL th_ringbuf_grow(qringbuf_t *buf, const size_t n)
+BOOL th_ringbuf_grow(th_ringbuf_t *buf, const size_t n)
 {
     buf->data = (char **) th_realloc(buf->data, (buf->size + n) * sizeof(char *));
     if (buf->data != NULL)
@@ -549,7 +569,7 @@
 }
 
 
-void th_ringbuf_free(qringbuf_t *buf)
+void th_ringbuf_free(th_ringbuf_t *buf)
 {
     int i;
     
@@ -564,7 +584,7 @@
 }
 
 
-void th_ringbuf_add(qringbuf_t *buf, void *ptr)
+void th_ringbuf_add(th_ringbuf_t *buf, void *ptr)
 {
     if (buf->n < buf->size)
         buf->n++;
--- a/th_util.h	Sat Feb 07 00:33:41 2015 +0200
+++ b/th_util.h	Sat Feb 07 01:39:20 2015 +0200
@@ -155,6 +155,7 @@
 th_llist_t * th_llist_new(void *data);
 void      th_llist_free(th_llist_t *list);
 void      th_llist_free_func(th_llist_t *list, void (*freefunc)(void *data));
+void      th_llist_free_func_node(th_llist_t *list, void (*freefunc)(th_llist_t *node));
 
 void      th_llist_append_node(th_llist_t **list, th_llist_t *node);
 th_llist_t * th_llist_append(th_llist_t **list, void *data);
@@ -182,12 +183,12 @@
     char **data;
     int n, size;
     void (*deallocator)(void *);
-} qringbuf_t;
+} th_ringbuf_t;
 
-qringbuf_t * th_ringbuf_new(const size_t size, void (*mdeallocator)(void *));
-BOOL         th_ringbuf_grow(qringbuf_t *buf, const size_t n);
-void         th_ringbuf_free(qringbuf_t *buf);
-void         th_ringbuf_add(qringbuf_t *buf, void *ptr);
+th_ringbuf_t * th_ringbuf_new(const size_t size, void (*mdeallocator)(void *));
+BOOL         th_ringbuf_grow(th_ringbuf_t *buf, const size_t n);
+void         th_ringbuf_free(th_ringbuf_t *buf);
+void         th_ringbuf_add(th_ringbuf_t *buf, void *ptr);
 
 
 /* Growing buffers