diff --git a/src/utils/llist.c b/src/utils/llist.c
index e042c99df1c81bb3b55482f8a6b8b5470a20d388..f9bf722785dab30087c2c6e796858f3decd3f4a7 100644 (file)
--- a/src/utils/llist.c
+++ b/src/utils/llist.c
* private helper functions
*/
+static void
+llist_clear(sdb_llist_t *list)
+{
+ sdb_llist_elem_t *elem;
+
+ assert(list);
+ elem = list->head;
+ while (elem) {
+ sdb_llist_elem_t *tmp = elem->next;
+
+ sdb_object_deref(elem->obj);
+ free(elem);
+
+ elem = tmp;
+ }
+
+ list->head = list->tail = NULL;
+ list->length = 0;
+} /* llist_clear */
+
/* Insert a new element after 'elem'. If 'elem' is NULL, insert at the head of
* the list. */
static int
void
sdb_llist_destroy(sdb_llist_t *list)
{
- sdb_llist_elem_t *elem;
-
if (! list)
return;
pthread_rwlock_wrlock(&list->lock);
-
- elem = list->head;
- while (elem) {
- sdb_llist_elem_t *tmp = elem->next;
-
- sdb_object_deref(elem->obj);
- free(elem);
-
- elem = tmp;
- }
-
- list->head = list->tail = NULL;
- list->length = 0;
-
+ llist_clear(list);
pthread_rwlock_unlock(&list->lock);
pthread_rwlock_destroy(&list->lock);
free(list);
} /* sdb_llist_destroy */
+void
+sdb_llist_clear(sdb_llist_t *list)
+{
+ if (! list)
+ return;
+
+ pthread_rwlock_wrlock(&list->lock);
+ llist_clear(list);
+ pthread_rwlock_unlock(&list->lock);
+} /* sdb_llist_clear */
+
int
sdb_llist_append(sdb_llist_t *list, sdb_object_t *obj)
{