From 250b303a9e36f1ddcb3e3b28a130a8674839a3a7 Mon Sep 17 00:00:00 2001 From: Pixel Date: Thu, 17 Nov 2011 08:28:17 -0800 Subject: Since tasks can be on different task managers, one has to signal them a bit differently. --- includes/Task.h | 7 ++++++- src/Task.cc | 24 +++++++++++++++++++++++- src/TaskMan.cc | 2 +- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/includes/Task.h b/includes/Task.h index 22c522e..9244347 100644 --- a/includes/Task.h +++ b/includes/Task.h @@ -65,10 +65,15 @@ class TaskEvent : public BaseEvent { TaskEvent(Task * taskWaited); virtual ~TaskEvent(); void ack(); + void signal(); Task * taskWaited() { return m_taskWaited; } + void evt_cb(ev::async & w, int revents) { doSignal(); } + protected: + virtual void gotOwner(Task * task); private: Task * m_taskWaited; - bool m_ack; + bool m_ack, m_distant; + ev::async m_evt; }; class Async : public BaseEvent { diff --git a/src/Task.cc b/src/Task.cc index 3a6f8ad..b512e23 100644 --- a/src/Task.cc +++ b/src/Task.cc @@ -114,13 +114,35 @@ void Balau::Events::BaseEvent::doSignal() { } } -Balau::Events::TaskEvent::TaskEvent(Task * taskWaited) : m_taskWaited(taskWaited), m_ack(false) { +Balau::Events::TaskEvent::TaskEvent(Task * taskWaited) : m_taskWaited(taskWaited), m_ack(false), m_distant(false) { m_taskWaited->m_waitedBy.push_back(this); } +void Balau::Events::TaskEvent::signal() { + if (m_distant) + m_evt.send(); + doSignal(); +} + +void Balau::Events::TaskEvent::gotOwner(Task * task) { + TaskMan * tm = task->getMyTaskMan(); + + m_evt.stop(); + if (tm != m_taskWaited->getMyTaskMan()) { + m_evt.set(tm->getLoop()); + m_evt.set(this); + m_evt.start(); + m_distant = true; + } else { + m_distant = false; + } +} + Balau::Events::TaskEvent::~TaskEvent() { if (!m_ack) ack(); + if (m_distant) + m_evt.stop(); } void Balau::Events::TaskEvent::ack() { diff --git a/src/TaskMan.cc b/src/TaskMan.cc index 81811db..375a94d 100644 --- a/src/TaskMan.cc +++ b/src/TaskMan.cc @@ -173,7 +173,7 @@ void Balau::TaskMan::mainLoop() { Task::waitedByList_t::iterator i; for (i = t->m_waitedBy.begin(); i != t->m_waitedBy.end(); i++) { Events::TaskEvent * e = *i; - e->doSignal(); + e->signal(); } } } -- cgit v1.2.3