summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--includes/Handle.h6
-rw-r--r--src/Task.cc1
-rw-r--r--src/TaskMan.cc14
3 files changed, 13 insertions, 8 deletions
diff --git a/includes/Handle.h b/includes/Handle.h
index 3339699..9f1486a 100644
--- a/includes/Handle.h
+++ b/includes/Handle.h
@@ -42,10 +42,12 @@ class Handle {
class IO {
public:
+ IO() : m_h(NULL) { }
IO(Handle * h) { setHandle(h); }
- ~IO() { m_h->delRef(); }
+ ~IO() { if (m_h) m_h->delRef(); }
IO(const IO & io) { setHandle(io.m_h); }
- Handle * operator->() { return m_h; }
+ IO & operator=(const IO & io) { if (m_h) m_h->delRef(); setHandle(io.m_h); return *this; }
+ Handle * operator->() { Assert(m_h); return m_h; }
protected:
void setHandle(Handle * h) { m_h = h; m_h->addRef(); }
private:
diff --git a/src/Task.cc b/src/Task.cc
index d31f4e0..771063e 100644
--- a/src/Task.cc
+++ b/src/Task.cc
@@ -52,7 +52,6 @@ void Balau::Task::coroutine(void * arg) {
}
void Balau::Task::switchTo() {
- m_status = RUNNING;
void * oldTLS = g_tlsManager->getTLS();
g_tlsManager->setTLS(m_tls);
coro_transfer(&m_taskMan->m_returnContext, &m_ctx);
diff --git a/src/TaskMan.cc b/src/TaskMan.cc
index 3b715ce..5a0c1c1 100644
--- a/src/TaskMan.cc
+++ b/src/TaskMan.cc
@@ -48,17 +48,21 @@ void Balau::TaskMan::mainLoop() {
// 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;
- }
+ if ((t->getStatus() == Task::STOPPED) || (t->getStatus() == Task::FAULTED))
+ noWait = true;
}
// 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)
+ if (m_tasks.size() == 0)
noWait = true;
+ m_pendingLock.enter();
+ if (m_pendingAdd.size() != 0)
+ noWait = true;
+ m_pendingLock.leave();
+
// libev's event "loop". We always runs it once though.
ev_run(m_loop, noWait ? EVRUN_NOWAIT : EVRUN_ONCE);