From bc8167eb99bc6febc96f4dab0bbce32186f30c16 Mon Sep 17 00:00:00 2001 From: John Crispin Date: Mon, 18 Nov 2013 11:15:19 +0100 Subject: [PATCH] runqueue: add a function that allows adding jobs to the front of the runqueue Signed-off-by: John Crispin --- runqueue.c | 17 +++++++++++++++-- runqueue.h | 1 + safe_list.c | 6 ++++++ safe_list.h | 1 + 4 files changed, 23 insertions(+), 2 deletions(-) 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) \