diff options
author | Pixel <Pixel> | 2001-11-12 22:20:50 +0000 |
---|---|---|
committer | Pixel <Pixel> | 2001-11-12 22:20:50 +0000 |
commit | ae4d1cfcbbe4c6130bd6370a03f546993a37f567 (patch) | |
tree | a423eced8aab74e0ed121ad1b3e828247ac5bb34 /lib | |
parent | e57c35f00e5eba0ee5199997238cf3179a89c4d2 (diff) |
Cleaning includes, progressing taskman...
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Task.cc | 34 | ||||
-rw-r--r-- | lib/TaskMan.cc | 53 |
2 files changed, 63 insertions, 24 deletions
diff --git a/lib/Task.cc b/lib/Task.cc index c34d0e3..2db8ce5 100644 --- a/lib/Task.cc +++ b/lib/Task.cc @@ -37,26 +37,24 @@ String Task::GetName() { return "Unknow Task"; } -int Task::Suspend() throw (GeneralException) { - int r; - +void Task::Suspend() throw (GeneralException) { cerr << "Suspending task " << GetName() << "...\n"; - suspended = true; - - r = setjmp(env); - - if (!r) throw TaskSwitch(); - - return r; + throw TaskSwitch(); } -void Task::Resume(int val) throw (GeneralException) { - cerr << "Resuming task " << GetName() << "...\n"; - if (suspended) { - suspended = false; - longjmp(env, val); - } else { - throw GeneralException(String("Task ") + GetName() + " was not suspended."); - } +void WaitFor(Handle * h) { + w4ha.push_back(h); +} + +void WaitFor(Task * t) { + w4ta.push_back(t); +} + +void WaitFor(pid_t p) { + w4pr.push_back(p); +} + +void WaitFor(struct timeval t) { + w4to.push_back(t); } diff --git a/lib/TaskMan.cc b/lib/TaskMan.cc index f8ba303..9abffb1 100644 --- a/lib/TaskMan.cc +++ b/lib/TaskMan.cc @@ -1,18 +1,59 @@ -#include <TaskMan.h> +#include <signal.h> +#include "TaskMan.h" -bool TaskMan::Inited = false; +bool TaskMan::inited = false; + +static got_sigchild = 0; + +void taskman_sigchild(int sig) { + got_sigchild = 1; + signal(SIGCHILD, taskman_sigchild); +} TaskMan::TaskMan() throw (GeneralException) { - if (Inited) { - throw GeneralException("Another Task Manager is already running, aborting."); + throw GeneralException("You can't instanciate a Task Manager."); +} + +void TaskMan::Init() throw (GeneralException) { + if (inited) { + throw GeneralException("Task Manager already initialised."); } - Inited = true; + signal(SIGCHILD, taskman_sigchild); + + inited = true; + number = 0; } int TaskMan::AddTask(Task * t) { + TaskList.push_back(t); + number++; + + return 0; +} + +int TaskMan::RemoveTask(Task * t) { + int i; + for (i = 0; i < number; i++) { + if (TaskList[i] == t) { + TaskList.erase(i); + number--; + return 0; + } + } + return -1; } -void TaskMan::MainLoop() { +void TaskMan::MainLoop() throw (GeneralException) { + while (1) { + if (number == 0) { + throw GeneralException("TaskMan: No more task to manage."); + } + +#ifdef HAVE_POLL + +#else +#endif + } } |