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 | |
parent | 43b4c9aaf56aefdc55c4b6c1df78e30cdcf3988f (diff) |
bus: implement full method call timeout logic
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/prioq.c | 20 | ||||
-rw-r--r-- | src/shared/prioq.h | 1 |
2 files changed, 19 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 { diff --git a/src/shared/prioq.h b/src/shared/prioq.h index 1b5b05e7c7..17679b2aaf 100644 --- a/src/shared/prioq.h +++ b/src/shared/prioq.h @@ -27,6 +27,7 @@ typedef struct Prioq Prioq; Prioq *prioq_new(compare_func_t compare); void prioq_free(Prioq *q); +int prioq_ensure_allocated(Prioq **q, compare_func_t compare_func); int prioq_put(Prioq *q, void *data, unsigned *idx); int prioq_remove(Prioq *q, void *data, unsigned *idx); |