From c52b8398d68a87d8fac858f6681dee5f0b09289d Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Thu, 2 Jan 2014 01:43:21 +0000 Subject: [PATCH] sched: Do not shadow task_info in struct task. All fields of struct task_info have direct counterparts in struct task. The fields of struct task are initialized in task_register() to the corresponding fields of struct task_info. It's easier to just embed a task_info structure in struct task instead. This also guarantees that task_register() stays correct in case another field is added to struct task_info. --- sched.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/sched.c b/sched.c index 0a1cff28..1280e07e 100644 --- a/sched.c +++ b/sched.c @@ -19,12 +19,10 @@ #include "error.h" struct task { - /** The task name supplied when the task was registered(). */ + /** A copy of the task name supplied when the task was registered. */ char *name; - /** Copied from the task_info struct during task_register(). */ - void (*pre_select)(struct sched *s, struct task *t); - /** Copied from the task_info struct during task_register(). */ - int (*post_select)(struct sched *s, struct task *t); + /** Copied during task_register(). */ + struct task_info info; /** Whether this task is active (>=0) or in error state (<0). */ int status; /** Position of the task in the task list of the scheduler. */ @@ -33,8 +31,6 @@ struct task { int notification; /** True if task is in error state and exit status has been queried. */ bool dead; - /** Usually a pointer to the struct containing this task. */ - void *context; }; static struct timeval now_struct; @@ -55,8 +51,8 @@ static void sched_preselect(struct sched *s) continue; if (t->notification != 0) sched_min_delay(s); - if (t->pre_select) - t->pre_select(s, t); + if (t->info.pre_select) + t->info.pre_select(s, t); } } @@ -72,13 +68,13 @@ static void unlink_and_free_task(struct task *t) static inline void call_post_select(struct sched *s, struct task *t) { #ifndef SCHED_DEBUG - t->status = t->post_select(s, t); + t->status = t->info.post_select(s, t); #else struct timeval t1, t2, diff; unsigned long pst; clock_get_realtime(&t1); - t->status = t->post_select(s, t); + t->status = t->info.post_select(s, t); clock_get_realtime(&t2); tv_diff(&t1, &t2, &diff); pst = tv2ms(&diff); @@ -240,13 +236,11 @@ struct task *task_register(struct task_info *info, struct sched *s) if (!s->task_list.next) INIT_LIST_HEAD(&s->task_list); + t->info = *info; t->name = para_strdup(info->name); t->notification = 0; t->status = 0; t->dead = false; - t->pre_select = info->pre_select; - t->post_select = info->post_select; - t->context = info->context; list_add_tail(&t->node, &s->task_list); return t; } @@ -261,7 +255,7 @@ struct task *task_register(struct task_info *info, struct sched *s) */ void *task_context(struct task *t) { - return t->context; + return t->info.context; } /** -- 2.39.2