diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-03-21 22:50:25 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-03-21 22:53:29 +0100 |
commit | e3017af97310da024ffb378ed155bc1676922ce7 (patch) | |
tree | a09b0a555b89f7ec00d0ab62294770db99c5642a /src/shared/prioq.c | |
parent | 43b4c9aaf56aefdc55c4b6c1df78e30cdcf3988f (diff) |
bus: implement full method call timeout logic
Diffstat (limited to 'src/shared/prioq.c')
-rw-r--r-- | src/shared/prioq.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/shared/prioq.c b/src/shared/prioq.c index fe91324d9b..b7d745990c 100644 --- a/src/shared/prioq.c +++ b/src/shared/prioq.c @@ -53,6 +53,19 @@ void prioq_free(Prioq *q) { free(q); } +int prioq_ensure_allocated(Prioq **q, compare_func_t compare_func) { + assert(q); + + if (*q) + return 0; + + *q = prioq_new(compare_func); + if (!*q) + return -ENOMEM; + + return 0; +} + static void swap(Prioq *q, unsigned j, unsigned k) { void *saved_data; unsigned *saved_idx; @@ -204,9 +217,12 @@ static struct prioq_item* find_item(Prioq *q, void *data, unsigned *idx) { assert(q); if (idx) { - assert(*idx < q->n_items); + if (*idx > q->n_items) + return NULL; + i = q->items + *idx; - assert(i->data == data); + if (i->data != data) + return NULL; return i; } else { |