X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=sched.c;h=c5b2c5ea1b4badf8b5f2e02fe94a03c9cdb6421f;hp=9db7c092e0209ac542283980773a9519a4f3b49a;hb=7d1805d1559e08e0af701155574aef220925d411;hpb=2a8029478dfc65f0c935d864faf4aea9e3deb27d diff --git a/sched.c b/sched.c index 9db7c092..c5b2c5ea 100644 --- a/sched.c +++ b/sched.c @@ -10,13 +10,19 @@ struct list_head pre_select_list; struct list_head post_select_list; +static struct timeval now_struct; +struct timeval *now = &now_struct; + static void sched_preselect(struct sched *s) { struct task *t, *tmp; again: list_for_each_entry_safe(t, tmp, &pre_select_list, pre_select_node) { t->pre_select(s, t); - if (t->ret > 0 || !t->event_handler) +// PARA_INFO_LOG("%s \n", t->status); + if (t->ret > 0) + continue; + if (!t->event_handler) continue; t->event_handler(t); goto again; @@ -29,6 +35,7 @@ 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); +// PARA_INFO_LOG("%s: %d\n", t->status, t->ret); if (t->ret > 0 || !t->event_handler) continue; t->event_handler(t); @@ -38,7 +45,7 @@ static void sched_post_select(struct sched *s) int sched(struct sched *s) { - gettimeofday(&s->now, NULL); + gettimeofday(now, NULL); again: FD_ZERO(&s->rfds); FD_ZERO(&s->wfds); @@ -49,7 +56,7 @@ again: &s->wfds, &s->timeout); if (s->select_ret < 0) return s->select_ret; - gettimeofday(&s->now, NULL); + gettimeofday(now, NULL); sched_post_select(s); if (list_empty(&pre_select_list) && list_empty(&post_select_list)) return 0; @@ -61,17 +68,11 @@ void *register_task(struct task *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) - list_add_tail(&t->pre_select_node, &pre_select_list); - else - list_add(&t->pre_select_node, &pre_select_list); + list_add(&t->pre_select_node, &pre_select_list); } if (t->post_select) { PARA_DEBUG_LOG("post_select: %p\n", &t->pre_select); - if (t->flags & POST_ADD_TAIL) - list_add_tail(&t->post_select_node, &post_select_list); - else - list_add(&t->post_select_node, &post_select_list); + list_add(&t->post_select_node, &post_select_list); } return t; } @@ -102,5 +103,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\tpre\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\tpost\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; +}