From b0ab39b0d25bd4cd13afd33a72026b78f9e2f660 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Mon, 31 Mar 2008 13:50:43 +0200 Subject: [PATCH] sched.c: Add checks for empty lists. This allows to call shed_shutdown() from the pre/post select hooks of the tasks. --- sched.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sched.c b/sched.c index 90df5933..869c94c0 100644 --- a/sched.c +++ b/sched.c @@ -54,6 +54,14 @@ static void sched_preselect(struct sched *s) // PARA_INFO_LOG("%s \n", t->status); if (t->error >= 0) continue; + /* + * We have to check whether the list is empty because the call + * to ->pre_select() might have called sched_shutdown(). In + * this case t has been unregistered already, so we must not + * unregister it again. + */ + if (list_empty(&pre_select_list)) + return; unregister_task(t); } } @@ -67,6 +75,9 @@ static void sched_post_select(struct sched *s) // PARA_INFO_LOG("%s: %d\n", t->status, t->ret); if (t->error >= 0) continue; + /* nec., see sched_preselect() */ + if (list_empty(&post_select_list)) + return; unregister_task(t); } } @@ -99,6 +110,8 @@ again: s->timeout = s->default_timeout; s->max_fileno = -1; sched_preselect(s); + if (list_empty(&pre_select_list) && list_empty(&post_select_list)) + return 0; ret = para_select(s->max_fileno + 1, &s->rfds, &s->wfds, &s->timeout); if (ret < 0) return ret; -- 2.39.2