summaryrefslogtreecommitdiff
path: root/lib/TaskMan.cc
diff options
context:
space:
mode:
authorPixel <Pixel>2001-11-13 11:50:37 +0000
committerPixel <Pixel>2001-11-13 11:50:37 +0000
commit9235fbc2a736da2c68eb2dc0a3c1007b4a202d5e (patch)
tree4045976599c1738646e6debccefa90d00107a42e /lib/TaskMan.cc
parent701e4e617e00e7f0ed4f07c1c4bcc20f6fb6ce4d (diff)
Still working on task system.
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++;
+ }
+
+
}
}