From 1d9def9edae0011eeee8f83dc32fb3797ca2f46b Mon Sep 17 00:00:00 2001 From: Pixel Date: Fri, 7 Oct 2011 15:36:12 -0700 Subject: 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 (!) --- src/TaskMan.cc | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) (limited to 'src/TaskMan.cc') 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 defaultTaskMan(50); static Balau::LocalTmpl 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 } -- cgit v1.2.3