summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: be8fe81)
raw | patch | inline | side by side (parent: be8fe81)
author | Sebastian Harl <sh@tokkee.org> | |
Mon, 30 Sep 2013 16:16:26 +0000 (18:16 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Mon, 30 Sep 2013 16:16:26 +0000 (18:16 +0200) |
Lookups should be more flexible than comparing two objects.
src/include/utils/llist.h | patch | blob | history | |
src/utils/llist.c | patch | blob | history |
index 4bf9d605ad74e8d46e28c262a8c92470acf6dc47..bd44d44c5053870b726b575ee7452a909e03d149 100644 (file)
typedef struct sdb_llist_iter sdb_llist_iter_t;
typedef int (*sdb_llist_cmp_cb)(const sdb_object_t *, const sdb_object_t *);
+typedef int (*sdb_llist_lookup_cb)(const sdb_object_t *, void *user_data);
/*
* sdb_llist_create, sdb_llist_destroy:
*/
sdb_object_t *
sdb_llist_search(sdb_llist_t *list,
- const sdb_object_t *key, sdb_llist_cmp_cb);
+ sdb_llist_lookup_cb lookup, void *user_data);
/*
* sdb_llist_search_by_name:
diff --git a/src/utils/llist.c b/src/utils/llist.c
index dfc8fb99d18ecfeb6e38cc0a7339426854691704..613e53cc8a601701318560cc34a5947f29e365a5 100644 (file)
--- a/src/utils/llist.c
+++ b/src/utils/llist.c
sdb_object_t *
sdb_llist_search(sdb_llist_t *list,
- const sdb_object_t *key, sdb_llist_cmp_cb compare)
+ sdb_llist_lookup_cb lookup, void *user_data)
{
sdb_llist_elem_t *elem;
- if ((! list) || (! compare))
+ if ((! list) || (! lookup))
return NULL;
pthread_rwlock_rdlock(&list->lock);
for (elem = list->head; elem; elem = elem->next)
- if (! compare(elem->obj, key))
+ if (! lookup(elem->obj, user_data))
break;
pthread_rwlock_unlock(&list->lock);
-
if (elem)
return elem->obj;
return NULL;