X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=sched.c;h=ae6b2a9d3cb0ac6425d94482fc7892641fca5df8;hp=fb0d4d63eacda82cb4e0779d72daa56c2634a324;hb=6df282b25d3ca0f2a55dd09546d0efc42a437ace;hpb=ba0c0797c76a2c94cb4a9f6938274fea5ba0226f diff --git a/sched.c b/sched.c index fb0d4d63..ae6b2a9d 100644 --- a/sched.c +++ b/sched.c @@ -18,6 +18,25 @@ #include "time.h" #include "error.h" +struct task { + /** The task name supplied when the task was registered(). */ + char name[255]; + /** 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); + /** Whether this task is active (>=0) or in error state (<0). */ + int error; + /** Position of the task in the task list of the scheduler. */ + struct list_head node; + /** If less than zero, the task was notified by another 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; struct timeval *now = &now_struct; @@ -43,7 +62,7 @@ static void sched_preselect(struct sched *s) static void unlink_and_free_task(struct task *t) { - PARA_INFO_LOG("freeing task %s\n", t->status); + PARA_INFO_LOG("freeing task %s\n", t->name); list_del(&t->node); free(t); } @@ -64,7 +83,7 @@ static inline void call_post_select(struct sched *s, struct task *t) pst = tv2ms(&diff); if (pst > 50) PARA_WARNING_LOG("%s: post_select time: %lums\n", - t->status, pst); + t->name, pst); #endif } @@ -197,7 +216,7 @@ void sched_shutdown(struct sched *s) if (t->error >= 0) /* The task list should contain only terminated tasks. */ PARA_WARNING_LOG("shutting down running task %s\n", - t->status); + t->name); unlink_and_free_task(t); } } @@ -220,8 +239,8 @@ struct task *task_register(struct task_info *info, struct sched *s) if (!s->task_list.next) INIT_LIST_HEAD(&s->task_list); - snprintf(t->status, sizeof(t->status) - 1, "%s", info->name); - t->status[sizeof(t->status) - 1] = '\0'; + snprintf(t->name, sizeof(t->name) - 1, "%s", info->name); + t->name[sizeof(t->name) - 1] = '\0'; t->notification = 0; t->error = 0; t->dead = false; @@ -264,7 +283,7 @@ char *get_task_list(struct sched *s) char *tmp_msg; tmp_msg = make_message("%s%p\t%s\t%s\n", msg? msg : "", t, t->error < 0? (t->dead? "dead" : "zombie") : "running", - t->status); + t->name); free(msg); msg = tmp_msg; } @@ -295,7 +314,7 @@ void task_notify(struct task *t, int err) assert(err > 0); if (t->notification == -err) /* ignore subsequent notifications */ return; - PARA_INFO_LOG("notifying task %s: %s\n", t->status, para_strerror(err)); + PARA_INFO_LOG("notifying task %s: %s\n", t->name, para_strerror(err)); t->notification = -err; }