runqueue: add a function that allows adding jobs to the front of the runqueue

Signed-off-by: John Crispin <blogic@openwrt.org>
This commit is contained in:
John Crispin 2013-11-18 11:15:19 +01:00 committed by Felix Fietkau
parent a34c8f6918
commit bc8167eb99
4 changed files with 23 additions and 2 deletions

View file

@ -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;

View file

@ -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);

View file

@ -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;

View file

@ -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) \