summaryrefslogtreecommitdiff
path: root/src/TaskMan.cc
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2011-10-07 15:36:12 -0700
committerPixel <pixel@nobis-crew.org>2011-10-07 15:36:12 -0700
commit1d9def9edae0011eeee8f83dc32fb3797ca2f46b (patch)
tree29077945287dd4b0c13269b9f3e5dc97936551f9 /src/TaskMan.cc
parent5a283e5b2b523d53e3504292c386b534dc74386a (diff)
More work in the Task manager.
Also fixing a few bugs linked with the printer and TLS. Removed flto from compilation flags: this actually creates bad code (!)
Diffstat (limited to 'src/TaskMan.cc')
-rw-r--r--src/TaskMan.cc48
1 files changed, 47 insertions, 1 deletions
diff --git a/src/TaskMan.cc b/src/TaskMan.cc
index 783c683..bbaf35c 100644
--- a/src/TaskMan.cc
+++ b/src/TaskMan.cc
@@ -1,11 +1,12 @@
#include "TaskMan.h"
+#include "Task.h"
#include "Main.h"
#include "Local.h"
static Balau::DefaultTmpl<Balau::TaskMan> defaultTaskMan(50);
static Balau::LocalTmpl<Balau::TaskMan> localTaskMan;
-Balau::TaskMan::TaskMan() {
+Balau::TaskMan::TaskMan() : stopped(false) {
coro_create(&returnContext, 0, 0, 0, 0);
if (!localTaskMan.getGlobal())
localTaskMan.setGlobal(this);
@@ -18,4 +19,49 @@ Balau::TaskMan::~TaskMan() {
}
void Balau::TaskMan::mainLoop() {
+ // We need at least one round before bailing :)
+ do {
+ taskList::iterator i;
+ Task * t;
+
+ // lock pending
+ // Adding tasks that were added, maybe from other threads
+ for (i = pendingAdd.begin(); i != pendingAdd.end(); i++) {
+ Assert(tasks.find(*i) == tasks.end());
+ tasks.insert(*i);
+ }
+ pendingAdd.clear();
+ // unlock pending
+
+ // checking "STARTING" tasks, and running them once
+ for (i = tasks.begin(); i != tasks.end(); i++) {
+ t = *i;
+ if (t->getStatus() == Task::STARTING) {
+ t->switchTo();
+ }
+ }
+
+ // That's probably where we poll for events
+
+ // checking "STOPPED" tasks, and destroying them
+ bool didDelete;
+ do {
+ didDelete = false;
+ for (i = tasks.begin(); i != tasks.end(); i++) {
+ t = *i;
+ if ((t->getStatus() == Task::STOPPED) || (t->getStatus() == Task::FAULTED)) {
+ delete t;
+ tasks.erase(i);
+ didDelete = true;
+ break;
+ }
+ }
+ } while (didDelete);
+ } while (!stopped && tasks.size() != 0);
+}
+
+void Balau::TaskMan::registerTask(Balau::Task * t) {
+ // lock pending
+ pendingAdd.insert(t);
+ // unlock pending
}