diff options
author | Pixel <Pixel> | 2001-11-23 11:26:50 +0000 |
---|---|---|
committer | Pixel <Pixel> | 2001-11-23 11:26:50 +0000 |
commit | 1311938cc52369b8631c29f83a9ecdf4a5f12f19 (patch) | |
tree | 4ec27df25d3df977631e62a82c11fd387a28b8c2 /lib/TaskMan.cc | |
parent | 0497d21e5b7b483259642aad1f23392995863c17 (diff) |
Last modifications...
Diffstat (limited to 'lib/TaskMan.cc')
-rw-r--r-- | lib/TaskMan.cc | 75 |
1 files changed, 39 insertions, 36 deletions
diff --git a/lib/TaskMan.cc b/lib/TaskMan.cc index ded359a..1af9234 100644 --- a/lib/TaskMan.cc +++ b/lib/TaskMan.cc @@ -4,6 +4,7 @@ #include "TaskMan.h" vector<Task *> TaskMan::TaskList; +vector<Task *> TaskMan::Zombies; int TaskMan::number = 0; bool TaskMan::inited = false; @@ -30,59 +31,61 @@ void TaskMan::Init() throw (GeneralException) { } int TaskMan::AddTask(Task * t) { + if (!inited) { + Init(); + } TaskList.push_back(t); number++; return 0; } -int TaskMan::RemoveTask(Task * t) { - int i; +void TaskMan::MainLoop() throw (GeneralException) { + TaskList_t::iterator p; + Task * t; - for (i = 0; i < number; i++) { - if (TaskList[i] == t) { - TaskList.erase(&TaskList[i]); - number--; - return 0; - } + int no_burst; + + if (!inited) { + Init(); } - return -1; -} - -void TaskMan::MainLoop() throw (GeneralException) { - Task ** p, * t; while (1) { + cerr << "TaskMan: Begin of main loop with " << number << " task to handle.\n"; + if (number == 0) { throw GeneralException("TaskMan: No more task to manage."); } - p = TaskList.begin(); - - while (1) { - t = *p; - -#ifdef HAVE_POLL -#else -#endif + no_burst = 0; + while (!no_burst) { + no_burst = 1; + /* First, we will check for any burning task and run 'em */ + for (p = TaskList.begin(); p && (p != TaskList.end()); p++) { + t = *p; - try { - t->Run(); - } - catch (TaskSwitch) { - continue; - } - if (t->GetState() == TASK_DONE) { - TaskList.erase(p); - } + if (t->GetState() == TASK_BURST) { + t->Run(); + } - if (p == TaskList.end()) { - break; + if (t->GetState() == TASK_BURST) { + no_burst = 0; + } else if (t->GetState() == TASK_DONE) { + TaskList.erase(p); + number--; + p--; + if (t->HasToClean()) { + delete t; + } else { + Zombies.push_back(t); + } + } } - - p++; } - - } + +#ifdef HAVE_POLL +#else +#endif + } |