From 9235fbc2a736da2c68eb2dc0a3c1007b4a202d5e Mon Sep 17 00:00:00 2001 From: Pixel Date: Tue, 13 Nov 2001 11:50:37 +0000 Subject: Still working on task system. --- lib/TaskMan.cc | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) (limited to 'lib/TaskMan.cc') diff --git a/lib/TaskMan.cc b/lib/TaskMan.cc index 9abffb1..6a38491 100644 --- a/lib/TaskMan.cc +++ b/lib/TaskMan.cc @@ -1,13 +1,19 @@ #include +#include +#include #include "TaskMan.h" bool TaskMan::inited = false; -static got_sigchild = 0; +static int got_sigchild = 0; +static vector process; +static int nbprocess = 0; void taskman_sigchild(int sig) { got_sigchild = 1; - signal(SIGCHILD, taskman_sigchild); + process.push_back(wait(NULL)); + signal(SIGCHLD, taskman_sigchild); + nbprocess++; } TaskMan::TaskMan() throw (GeneralException) { @@ -19,7 +25,7 @@ void TaskMan::Init() throw (GeneralException) { throw GeneralException("Task Manager already initialised."); } - signal(SIGCHILD, taskman_sigchild); + signal(SIGCHLD, taskman_sigchild); inited = true; number = 0; @@ -37,7 +43,7 @@ int TaskMan::RemoveTask(Task * t) { for (i = 0; i < number; i++) { if (TaskList[i] == t) { - TaskList.erase(i); + TaskList.erase(&TaskList[i]); number--; return 0; } @@ -46,14 +52,39 @@ int TaskMan::RemoveTask(Task * t) { } void TaskMan::MainLoop() throw (GeneralException) { + Task ** p, * t; + while (1) { if (number == 0) { throw GeneralException("TaskMan: No more task to manage."); } - -#ifdef HAVE_POLL + p = TaskList.begin(); + + while (1) { + t = *p; + +#ifdef HAVE_POLL #else -#endif +#endif + + try { + t->Do(); + } + catch (TaskSwitch) { + continue; + } + if (t->GetState() == TASK_DONE) { + TaskList.erase(p); + } + + if (p == TaskList.end()) { + break; + } + + p++; + } + + } } -- cgit v1.2.3