]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
sched.c: Add checks for empty lists.
authorAndre Noll <maan@systemlinux.org>
Mon, 31 Mar 2008 11:50:43 +0000 (13:50 +0200)
committerAndre Noll <maan@systemlinux.org>
Mon, 31 Mar 2008 11:50:43 +0000 (13:50 +0200)
This allows to call shed_shutdown() from the pre/post select hooks
of the tasks.

sched.c

diff --git a/sched.c b/sched.c
index 90df5933689c377ad2c570e36bb340eda74e9dae..869c94c099d23a65c65163eea7f7a5b296fbd687 100644 (file)
--- 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;