From 965148b43b5b859934b7af2e8447ba1026a43a19 Mon Sep 17 00:00:00 2001 From: Pixel Date: Mon, 10 Oct 2011 19:36:55 -0700 Subject: Adding the basic "Handle" structure, and adding an early version of Input. Renamed suspend() to yield(). Fixed a couple of bugs, and reorganized slightly some code. --- src/TaskMan.cc | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/TaskMan.cc') diff --git a/src/TaskMan.cc b/src/TaskMan.cc index fd0246f..ea9c0fb 100644 --- a/src/TaskMan.cc +++ b/src/TaskMan.cc @@ -29,15 +29,24 @@ void Balau::TaskMan::mainLoop() { taskList_t::iterator iL; taskHash_t::iterator iH; Task * t; + bool noWait = false; - // checking "STARTING" tasks, and running them once + // checking "STARTING" tasks, and running them once; also try to build the status of the noWait boolean. for (iH = m_tasks.begin(); iH != m_tasks.end(); iH++) { t = *iH; - if (t->getStatus() == Task::STARTING) + if (t->getStatus() == Task::STARTING) { t->switchTo(); + if ((t->getStatus() == Task::STOPPED) || (t->getStatus() == Task::FAULTED)) + noWait = true; + } } - ev_run(m_loop, EVRUN_ONCE); + // probably means we have pending tasks; or none at all, for some reason. Don't wait on it forever. + if (!noWait && m_tasks.size() == 0) + noWait = true; + + // libev's event "loop". We always runs it once though. + ev_run(m_loop, noWait ? EVRUN_NOWAIT : EVRUN_ONCE); // let's check who got signaled, and call them for (iH = m_signaledTasks.begin(); iH != m_signaledTasks.end(); iH++) { -- cgit v1.2.3