summaryrefslogtreecommitdiff
path: root/src/LuaTask.cc
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2012-04-03 08:46:21 -0700
committerPixel <pixel@nobis-crew.org>2012-04-03 08:46:21 -0700
commit37221dc091725c6fea09181b845308ab8f26c795 (patch)
treef877eb7f70f2f9ec021fd04720d7bd0c937dbab7 /src/LuaTask.cc
parent7d5f246ae7310055d39ea13ff395d830e3c27a60 (diff)
Reworking a bit the way the queues are working, and thus, the way the LuaTMainTask queue works.
Diffstat (limited to 'src/LuaTask.cc')
-rw-r--r--src/LuaTask.cc24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/LuaTask.cc b/src/LuaTask.cc
index 9a7e978..acf63b5 100644
--- a/src/LuaTask.cc
+++ b/src/LuaTask.cc
@@ -2,6 +2,10 @@
#include "Main.h"
#include "TaskMan.h"
+class LuaTaskDummy : public Balau::LuaExecCell {
+ virtual void run(Balau::Lua &) { }
+};
+
Balau::LuaMainTask::LuaMainTask() : m_stopping(false) {
L.open_base();
L.open_table();
@@ -12,25 +16,29 @@ Balau::LuaMainTask::LuaMainTask() : m_stopping(false) {
L.open_jit();
}
+Balau::LuaMainTask::~LuaMainTask() {
+ L.close();
+}
+
void Balau::LuaMainTask::exec(LuaExecCell * cell) {
m_queue.push(cell);
- m_queueEvent.trigger();
}
void Balau::LuaMainTask::stop() {
Atomic::CmpXChgVal(&m_stopping, true, false);
- m_queueEvent.trigger();
+ exec(new LuaTaskDummy());
}
void Balau::LuaMainTask::Do() {
while (!m_stopping) {
- waitFor(&m_queueEvent);
-
LuaExecCell * cell;
- while ((cell = m_queue.pop(false)))
- createTask(new LuaTask(L.thread(), cell), this);
-
- yield();
+ while ((cell = m_queue.pop(false))) {
+ if (dynamic_cast<LuaTaskDummy *>(cell)) {
+ delete cell;
+ break;
+ }
+ TaskMan::createTask(new LuaTask(L.thread(), cell), this);
+ }
}
}