diff --git a/src/utils/llist.c b/src/utils/llist.c
index 0af9c8cb11bec4346b96c557275b4a813ccfd618..2dc7781cccab7f2ca8decd373461ae7e42999d0b 100644 (file)
--- a/src/utils/llist.c
+++ b/src/utils/llist.c
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif /* HAVE_CONFIG_H */
+
#include "utils/llist.h"
#include <assert.h>
return status;
} /* sdb_llist_insert_sorted */
+sdb_object_t *
+sdb_llist_get(sdb_llist_t *list, size_t i)
+{
+ sdb_llist_elem_t *elem;
+ size_t j;
+
+ if ((! list) || (i >= list->length))
+ return NULL;
+
+ for (elem = list->head, j = 0; j < i; elem = elem->next, ++j)
+ /* iterate */;
+
+ assert(elem);
+ return elem->obj;
+} /* sdb_llist_get */
+
sdb_object_t *
sdb_llist_search(sdb_llist_t *list,
sdb_llist_lookup_cb lookup, const void *user_data)
pthread_rwlock_rdlock(&iter->list->lock);
+ /* XXX: increment ref-cnt for this object?
+ * also: when letting an element take ownership of next and prev
+ * elements, this might be a fairly cheap way to implement a weak
+ * type of snapshotting */
+
obj = iter->elem->obj;
iter->elem = iter->elem->next;
return obj;
} /* sdb_llist_iter_get_next */
+int
+sdb_llist_iter_remove_current(sdb_llist_iter_t *iter)
+{
+ sdb_llist_elem_t *elem;
+
+ if ((! iter) || (! iter->list))
+ return -1;
+
+ pthread_rwlock_wrlock(&iter->list->lock);
+
+ if (! iter->elem) /* reached end of list */
+ elem = iter->list->tail;
+ else
+ elem = iter->elem->prev;
+ if (elem)
+ sdb_llist_remove_elem(iter->list, elem);
+
+ pthread_rwlock_unlock(&iter->list->lock);
+
+ if (! elem)
+ return -1;
+ return 0;
+} /* sdb_llist_iter_remove */
+
+size_t
+sdb_llist_len(sdb_llist_t *list)
+{
+ if (! list)
+ return 0;
+ return list->length;
+} /* sdb_llist_len */
+
/* vim: set tw=78 sw=4 ts=4 noexpandtab : */