summaryrefslogtreecommitdiff
path: root/lib/TaskMan.cc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/TaskMan.cc')
-rw-r--r--lib/TaskMan.cc45
1 files changed, 38 insertions, 7 deletions
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 <signal.h>
+#include <wait.h>
+#include <vector.h>
#include "TaskMan.h"
bool TaskMan::inited = false;
-static got_sigchild = 0;
+static int got_sigchild = 0;
+static vector<pid_t> 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++;
+ }
+
+
}
}