]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - sched.c
sched: Introduce task_status().
[paraslash.git] / sched.c
diff --git a/sched.c b/sched.c
index 6b8e09108308336676e48c4d8c9e84eb6e388431..fb0d4d63eacda82cb4e0779d72daa56c2634a324 100644 (file)
--- a/sched.c
+++ b/sched.c
@@ -45,8 +45,7 @@ static void unlink_and_free_task(struct task *t)
 {
        PARA_INFO_LOG("freeing task %s\n", t->status);
        list_del(&t->node);
-       if (t->owned_by_sched)
-               free(t);
+       free(t);
 }
 
 //#define SCHED_DEBUG 1
@@ -82,10 +81,7 @@ static unsigned sched_post_select(struct sched *s)
                }
                call_post_select(s, t);
                t->notification = 0;
-               if (t->error < 0) {
-                       if (!t->owned_by_sched)
-                               list_del(&t->node);
-               } else
+               if (t->error >= 0)
                        num_running_tasks++;
        }
        return num_running_tasks;
@@ -169,8 +165,6 @@ int task_reap(struct task **tptr)
        t = *tptr;
        if (!t)
                return 0;
-       if (!t->owned_by_sched)
-               return 0;
        if (t->error >= 0)
                return 0;
        if (t->dead) /* will be freed in sched_post_select() */
@@ -208,25 +202,6 @@ void sched_shutdown(struct sched *s)
        }
 }
 
-/**
- * Add a task to the scheduler. Deprecated.
- *
- * \param t The task to add.
- * \param s The scheduler instance to add the task to.
- *
- * \sa task::pre_select, task::post_select
- */
-void register_task(struct sched *s, struct task *t)
-{
-       PARA_INFO_LOG("registering %s (%p)\n", t->status, t);
-       assert(t->post_select);
-       t->notification = 0;
-       t->owned_by_sched = false;
-       if (!s->task_list.next)
-               INIT_LIST_HEAD(&s->task_list);
-       list_add_tail(&t->node, &s->task_list);
-}
-
 /**
  * Add a task to the scheduler task list.
  *
@@ -253,7 +228,6 @@ struct task *task_register(struct task_info *info, struct sched *s)
        t->pre_select = info->pre_select;
        t->post_select = info->post_select;
        t->context = info->context;
-       t->owned_by_sched = true;
        list_add_tail(&t->node, &s->task_list);
        return t;
 }
@@ -268,7 +242,6 @@ struct task *task_register(struct task_info *info, struct sched *s)
  */
 void *task_context(struct task *t)
 {
-       assert(t->owned_by_sched);
        return t->context;
 }
 
@@ -342,6 +315,25 @@ int task_get_notification(const struct task *t)
        return t->notification;
 }
 
+/**
+ * Return the status value of a task.
+ *
+ * \param t The task to get the status value from.
+ *
+ * \return Zero if task does not exist, one if task is running, negative error
+ * code if task has terminated.
+ */
+int task_status(const struct task *t)
+{
+       if (!t)
+               return 0;
+       if (t->dead)
+               return 0;
+       if (t->error >= 0)
+               return 1;
+       return t->error;
+}
+
 /**
  * Set the notification value of all tasks of a scheduler instance.
  *