]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - sched.c
sched.c: Add checks for empty lists.
[paraslash.git] / sched.c
diff --git a/sched.c b/sched.c
index 9976a11d2aa315f78ff88072c0a27d84ed35e58d..869c94c099d23a65c65163eea7f7a5b296fbd687 100644 (file)
--- a/sched.c
+++ b/sched.c
@@ -41,6 +41,8 @@ void unregister_task(struct task *t)
                list_del(&t->pre_select_node);
        if (t->post_select)
                list_del(&t->post_select_node);
+       if (t->error >= 0)
+               t->error = -E_TASK_KILLED;
 };
 
 
@@ -52,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);
        }
 }
@@ -65,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);
        }
 }
@@ -97,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;