From 18beadfdfb761e6a54be6093e65b66a431bacc19 Mon Sep 17 00:00:00 2001 From: Pixel Date: Wed, 16 Nov 2011 18:11:21 -0800 Subject: And with the new TaskScheduler system, let's add a way for a new task to stick on another one's thread, if needed. (and it is) --- includes/TaskMan.h | 6 +++--- src/TaskMan.cc | 10 ++++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/includes/TaskMan.h b/includes/TaskMan.h index afc2b8a..b9897e4 100644 --- a/includes/TaskMan.h +++ b/includes/TaskMan.h @@ -34,7 +34,7 @@ class TaskMan { static void stop(); void stopMe() { m_stopped = true; } private: - static void registerTask(Task * t); + static void registerTask(Task * t, Task * stick); void addToPending(Task * t); #ifndef _WIN32 coro_context m_returnContext; @@ -44,7 +44,7 @@ class TaskMan { friend class Task; friend class TaskScheduler; template - friend T * createTask(T * t); + friend T * createTask(T * t, Task * stick = NULL); struct taskHasher { size_t operator()(const Task * t) const { return reinterpret_cast(t); } }; typedef gnu::hash_set taskHash_t; taskHash_t m_tasks, m_signaledTasks; @@ -56,6 +56,6 @@ class TaskMan { }; template -T * createTask(T * t) { TaskMan::registerTask(t); Assert(dynamic_cast(t)); return t; } +T * createTask(T * t, Task * stick = NULL) { TaskMan::registerTask(t, stick); Assert(dynamic_cast(t)); return t; } }; diff --git a/src/TaskMan.cc b/src/TaskMan.cc index 8c99e52..630d845 100644 --- a/src/TaskMan.cc +++ b/src/TaskMan.cc @@ -216,8 +216,14 @@ void Balau::TaskMan::mainLoop() { Printer::elog(E_TASK, "TaskManager stopping."); } -void Balau::TaskMan::registerTask(Balau::Task * t) { - s_scheduler.registerTask(t); +void Balau::TaskMan::registerTask(Balau::Task * t, Balau::Task * stick) { + if (stick) { + TaskMan * tm = stick->getMyTaskMan(); + tm->addToPending(t); + tm->m_evt.send(); + } else { + s_scheduler.registerTask(t); + } } void Balau::TaskMan::addToPending(Balau::Task * t) { -- cgit v1.2.3