#include "time.h"
#include "error.h"
+struct task {
+ /** Copied from the task_info struct during task_register(). */
+ void (*pre_select)(struct sched *s, struct task *t);
+ /** Copied from the task_info struct during task_register(). */
+ int (*post_select)(struct sched *s, struct task *t);
+ /** Whether this task is active (>=0) or in error state (<0). */
+ int error;
+ /** Position of the task in the task list of the scheduler. */
+ struct list_head node;
+ /** The task name supplied when the task was registered(). */
+ char status[255];
+ /** If less than zero, the task was notified by another task. */
+ int notification;
+ /** True if task is in error state and exit status has been queried. */
+ bool dead;
+ /** Usually a pointer to the struct containing this task. */
+ void *context;
+};
+
static struct timeval now_struct;
struct timeval *now = &now_struct;
{
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
}
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;
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() */
}
}
-/**
- * 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.
*
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;
}
*/
void *task_context(struct task *t)
{
- assert(t->owned_by_sched);
return t->context;
}
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.
*