summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2012-04-06 11:40:55 -0700
committerPixel <pixel@nobis-crew.org>2012-04-06 11:40:55 -0700
commitf2cfa1707c713c7bb01d16f4c2c4d96803ea6793 (patch)
treea722f3ad52ec471520097c5bfbbf2ab8cb4e2603 /src
parent7fbb819bf6f590bf2337d2277f77487ef7a5ce86 (diff)
Making it simplier to register a task and wait for it. Also renamed createTask to registerTask, which makes way more sense.
Diffstat (limited to 'src')
-rw-r--r--src/HttpServer.cc2
-rw-r--r--src/LuaTask.cc2
-rw-r--r--src/Main.cc2
-rw-r--r--src/Task.cc9
-rw-r--r--src/TaskMan.cc5
5 files changed, 15 insertions, 5 deletions
diff --git a/src/HttpServer.cc b/src/HttpServer.cc
index 44c794e..2e3f703 100644
--- a/src/HttpServer.cc
+++ b/src/HttpServer.cc
@@ -594,7 +594,7 @@ typedef Balau::Listener<Balau::HttpWorker> HttpListener;
void Balau::HttpServer::start() {
AAssert(!m_started, "Don't start an HttpServer twice");
- m_listenerPtr = TaskMan::createTask(new HttpListener(m_port, m_local.to_charp(), this));
+ m_listenerPtr = TaskMan::registerTask(new HttpListener(m_port, m_local.to_charp(), this));
m_started = true;
}
diff --git a/src/LuaTask.cc b/src/LuaTask.cc
index 2641682..687c81a 100644
--- a/src/LuaTask.cc
+++ b/src/LuaTask.cc
@@ -51,7 +51,7 @@ void Balau::LuaMainTask::Do() {
delete cell;
return;
}
- TaskMan::createTask(new LuaTask(L.thread(), cell), this);
+ TaskMan::registerTask(new LuaTask(L.thread(), cell), this);
}
}
}
diff --git a/src/Main.cc b/src/Main.cc
index e1eae66..32b7cf8 100644
--- a/src/Main.cc
+++ b/src/Main.cc
@@ -60,7 +60,7 @@ int Balau::Main::bootstrap(int _argc, char ** _argv) {
try {
m_status = RUNNING;
- TaskMan::createTask(new MainTask());
+ TaskMan::registerTask(new MainTask());
r = TaskMan::getDefaultTaskMan()->mainLoop();
m_status = STOPPING;
}
diff --git a/src/Task.cc b/src/Task.cc
index 0a213be..f4db057 100644
--- a/src/Task.cc
+++ b/src/Task.cc
@@ -149,7 +149,14 @@ void Balau::Events::BaseEvent::doSignal() {
}
}
-Balau::Events::TaskEvent::TaskEvent(Task * taskWaited) : m_taskWaited(taskWaited), m_ack(false), m_distant(false) {
+Balau::Events::TaskEvent::TaskEvent(Task * taskWaited) : m_taskWaited(NULL), m_ack(false), m_distant(false) {
+ if (taskWaited)
+ attachToTask(taskWaited);
+}
+
+void Balau::Events::TaskEvent::attachToTask(Task * taskWaited) {
+ AAssert(!m_taskWaited, "You can't attach a TaskEvent twice.");
+ m_taskWaited = taskWaited;
ScopeLock lock(m_taskWaited->m_eventLock);
m_taskWaited->m_waitedBy.push_back(this);
}
diff --git a/src/TaskMan.cc b/src/TaskMan.cc
index d91581e..1695d39 100644
--- a/src/TaskMan.cc
+++ b/src/TaskMan.cc
@@ -331,11 +331,14 @@ int Balau::TaskMan::mainLoop() {
return m_stopCode;
}
-void Balau::TaskMan::registerTask(Balau::Task * t, Balau::Task * stick) {
+void Balau::TaskMan::iRegisterTask(Balau::Task * t, Balau::Task * stick, Events::TaskEvent * event) {
if (stick) {
+ IAssert(!event, "inconsistent");
TaskMan * tm = stick->getTaskMan();
tm->addToPending(t);
} else {
+ if (event)
+ event->attachToTask(t);
s_scheduler.registerTask(t);
}
}