X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=sched.c;h=879ab80820e56742815044d158f25aec965359db;hb=d46fe38dcada4108ed49a0e621376df0f7913fe3;hp=fad70132232268a2c9aade01c12b29e68f8987dc;hpb=2290d9be0703d3f83f38c2f100b1b41ec0790bb3;p=paraslash.git diff --git a/sched.c b/sched.c index fad70132..879ab808 100644 --- a/sched.c +++ b/sched.c @@ -16,16 +16,12 @@ static void sched_preselect(struct sched *s) again: list_for_each_entry_safe(t, tmp, &pre_select_list, pre_select_node) { t->pre_select(s, t); - if (t->ret > 0 || !t->error_handler) +// PARA_INFO_LOG("%s \n", t->status); + if (t->ret > 0) continue; - if (t->ret < 0) { - t->error_handler(t); - goto again; - } - if (!(t->flags & PRE_EOF_IS_ERROR)) + if (!t->event_handler) continue; - t->ret = -E_PRE_EOF; - t->error_handler(t); + t->event_handler(t); goto again; } } @@ -36,16 +32,10 @@ static void sched_post_select(struct sched *s) list_for_each_entry_safe(t, tmp, &post_select_list, post_select_node) { t->post_select(s, t); - if (t->ret > 0 || !t->error_handler) +// PARA_INFO_LOG("%s: %d\n", t->status, t->ret); + if (t->ret > 0 || !t->event_handler) continue; - if (t->ret < 0) { - t->error_handler(t); - continue; - } - if (!(t->flags & POST_EOF_IS_ERROR)) - continue; - t->ret = -E_POST_EOF; - t->error_handler(t); + t->event_handler(t); } } @@ -72,7 +62,7 @@ again: void *register_task(struct task *t) { - PARA_INFO_LOG("registering task %p\n", t); + PARA_INFO_LOG("registering %s (%p)\n", t->status, t); if (t->pre_select) { PARA_DEBUG_LOG("pre_select: %p\n", &t->pre_select); if (t->flags & PRE_ADD_TAIL) @@ -92,7 +82,7 @@ void *register_task(struct task *t) void unregister_task(struct task *t) { - PARA_INFO_LOG("unregistering task %p\n", t); + PARA_INFO_LOG("unregistering %s (%p)\n", t->status, t); if (t->pre_select) list_del(&t->pre_select_node); if (t->post_select) @@ -116,5 +106,49 @@ void sched_shutdown(void) unregister_task(t); }; +char *get_task_list(void) +{ + struct task *t, *tmp; + char *msg = NULL; + list_for_each_entry_safe(t, tmp, &pre_select_list, pre_select_node) { + char *tmp_msg; + tmp_msg = make_message("%s%p\t%s\n", msg? msg : "", t, t->status); + free(msg); + msg = tmp_msg; + } + list_for_each_entry_safe(t, tmp, &post_select_list, post_select_node) { + char *tmp_msg; + if (t->pre_select) + continue; + tmp_msg = make_message("%s%p\t%s\n", msg? msg : "", t, t->status); + free(msg); + msg = tmp_msg; + } + //PARA_DEBUG_LOG("task list:\n%s", msg); + return msg; +} -//char *get_tast_list(); +int kill_task(char *id) +{ + struct task *t, *tmp; + char buf[20]; + list_for_each_entry_safe(t, tmp, &pre_select_list, pre_select_node) { + sprintf(buf, "%p", t); + if (strcmp(id, buf)) + continue; + t->ret = -E_TASK_KILLED; + if (t->event_handler) + t->event_handler(t); + return 1; + } + list_for_each_entry_safe(t, tmp, &post_select_list, post_select_node) { + sprintf(buf, "%p", t); + if (strcmp(id, buf)) + continue; + t->ret = -E_TASK_KILLED; + if (t->event_handler) + t->event_handler(t); + return 1; + } + return -E_NO_SUCH_TASK; +}