From: John Crispin Date: Mon, 18 Nov 2013 10:15:19 +0000 (+0100) Subject: runqueue: add a function that allows adding jobs to the front of the runqueue X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=bc8167eb99bc6febc96f4dab0bbce32186f30c16;p=oweals%2Flibubox.git runqueue: add a function that allows adding jobs to the front of the runqueue Signed-off-by: John Crispin --- diff --git a/runqueue.c b/runqueue.c index 189a005..1784e30 100644 --- a/runqueue.c +++ b/runqueue.c @@ -145,7 +145,7 @@ __runqueue_task_timeout(struct uloop_timeout *timeout) runqueue_task_cancel(t, t->cancel_type); } -void runqueue_task_add(struct runqueue *q, struct runqueue_task *t, bool running) +static void _runqueue_task_add(struct runqueue *q, struct runqueue_task *t, bool running, bool first) { struct safe_list *head; @@ -166,7 +166,10 @@ void runqueue_task_add(struct runqueue *q, struct runqueue_task *t, bool running t->timeout.cb = __runqueue_task_timeout; t->q = q; - safe_list_add(&t->list, head); + if (first) + safe_list_add_first(&t->list, head); + else + safe_list_add(&t->list, head); t->cancelled = false; t->queued = true; t->running = running; @@ -175,6 +178,16 @@ void runqueue_task_add(struct runqueue *q, struct runqueue_task *t, bool running runqueue_start_next(q); } +void runqueue_task_add(struct runqueue *q, struct runqueue_task *t, bool running) +{ + _runqueue_task_add(q, t, running, 0); +} + +void runqueue_task_add_first(struct runqueue *q, struct runqueue_task *t, bool running) +{ + _runqueue_task_add(q, t, running, 1); +} + void runqueue_task_kill(struct runqueue_task *t) { struct runqueue *q = t->q; diff --git a/runqueue.h b/runqueue.h index 00ad1eb..0d4173d 100644 --- a/runqueue.h +++ b/runqueue.h @@ -100,6 +100,7 @@ void runqueue_stop(struct runqueue *q); void runqueue_resume(struct runqueue *q); void runqueue_task_add(struct runqueue *q, struct runqueue_task *t, bool running); +void runqueue_task_add_first(struct runqueue *q, struct runqueue_task *t, bool running); void runqueue_task_complete(struct runqueue_task *t); void runqueue_task_cancel(struct runqueue_task *t, int type); diff --git a/safe_list.c b/safe_list.c index f26b4dd..16f57e0 100644 --- a/safe_list.c +++ b/safe_list.c @@ -86,6 +86,12 @@ void safe_list_add(struct safe_list *list, struct safe_list *head) list_add_tail(&list->list, &head->list); } +void safe_list_add_first(struct safe_list *list, struct safe_list *head) +{ + list->i = NULL; + list_add(&list->list, &head->list); +} + void safe_list_del(struct safe_list *list) { struct safe_list_iterator *i, *next_i, **tail; diff --git a/safe_list.h b/safe_list.h index 3c8b61b..67b673d 100644 --- a/safe_list.h +++ b/safe_list.h @@ -42,6 +42,7 @@ int safe_list_for_each(struct safe_list *list, void *ctx); void safe_list_add(struct safe_list *list, struct safe_list *head); +void safe_list_add_first(struct safe_list *list, struct safe_list *head); void safe_list_del(struct safe_list *list); #define INIT_SAFE_LIST(_head) \