From c4b79e4b5448abcd04c1848e212a237e8b17c3de Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Thu, 9 May 2013 01:27:45 +0200 Subject: [PATCH] runqueue: move completion handler from runqueue_process to runqueue_task to make it more generic Signed-off-by: Felix Fietkau --- examples/runqueue-example.c | 6 +++--- runqueue.c | 6 ++---- runqueue.h | 3 ++- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/examples/runqueue-example.c b/examples/runqueue-example.c index 727463f..1ae184a 100644 --- a/examples/runqueue-example.c +++ b/examples/runqueue-example.c @@ -66,9 +66,9 @@ static void q_sleep_cancel(struct runqueue *q, struct runqueue_task *t, int type runqueue_process_cancel_cb(q, t, type); } -static void q_sleep_complete(struct runqueue *q, struct runqueue_process *p, int ret) +static void q_sleep_complete(struct runqueue *q, struct runqueue_task *p) { - struct sleeper *s = container_of(p, struct sleeper, proc); + struct sleeper *s = container_of(p, struct sleeper, proc.task); fprintf(stderr, "[%d/%d] finish 'sleep %d'\n", q->running_tasks, q->max_running_tasks, s->val); free(s); @@ -86,7 +86,7 @@ static void add_sleeper(int val) s = calloc(1, sizeof(*s)); s->proc.task.type = &sleeper_type; s->proc.task.run_timeout = 500; - s->proc.complete = q_sleep_complete; + s->proc.task.complete = q_sleep_complete; s->val = val; runqueue_task_add(&q, &s->proc.task, false); } diff --git a/runqueue.c b/runqueue.c index 5cc37bb..1bdb48e 100644 --- a/runqueue.c +++ b/runqueue.c @@ -186,6 +186,8 @@ void runqueue_task_kill(struct runqueue_task *t) runqueue_task_complete(t); if (running && t->type->kill) t->type->kill(q, t); + if (t->complete) + t->complete(q, t); runqueue_start_next(q); } @@ -220,11 +222,8 @@ static void __runqueue_proc_cb(struct uloop_process *p, int ret) { struct runqueue_process *t = container_of(p, struct runqueue_process, proc); - struct runqueue *q = t->task.q; runqueue_task_complete(&t->task); - if (t->complete) - t->complete(q, t, ret); } void runqueue_process_cancel_cb(struct runqueue *q, struct runqueue_task *t, int type) @@ -243,7 +242,6 @@ void runqueue_process_kill_cb(struct runqueue *q, struct runqueue_task *t) uloop_process_delete(&p->proc); kill(p->proc.pid, SIGKILL); - __runqueue_proc_cb(&p->proc, -1); } static const struct runqueue_task_type runqueue_proc_type = { diff --git a/runqueue.h b/runqueue.h index 127085f..00ad1eb 100644 --- a/runqueue.h +++ b/runqueue.h @@ -73,6 +73,8 @@ struct runqueue_task { const struct runqueue_task_type *type; struct runqueue *q; + void (*complete)(struct runqueue *q, struct runqueue_task *t); + struct uloop_timeout timeout; int run_timeout; int cancel_timeout; @@ -86,7 +88,6 @@ struct runqueue_task { struct runqueue_process { struct runqueue_task task; struct uloop_process proc; - void (*complete)(struct runqueue *q, struct runqueue_process *p, int ret); }; void runqueue_init(struct runqueue *q); -- 2.25.1