summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2012-04-03 16:05:07 -0700
committerPixel <pixel@nobis-crew.org>2012-04-03 16:05:07 -0700
commitb7c281e1d7c26d4414706d529862407d07e385c2 (patch)
tree5462876ddcd86787068753a8c6a40ca017cf88fa
parent532f3e7bae955f8da4c2028bc462134ed10ff414 (diff)
Having a slightly better mechanism for stopping the LuaMainTask, as well as some debugging messages.
-rw-r--r--includes/LuaTask.h3
-rw-r--r--src/LuaTask.cc24
2 files changed, 18 insertions, 9 deletions
diff --git a/includes/LuaTask.h b/includes/LuaTask.h
index 5058578..0d763de 100644
--- a/includes/LuaTask.h
+++ b/includes/LuaTask.h
@@ -11,7 +11,7 @@ class LuaMainTask;
class LuaExecCell {
public:
- LuaExecCell() : m_detached(false) { }
+ LuaExecCell();
void detach() { m_detached = true; }
void exec(LuaMainTask * mainTask);
protected:
@@ -61,7 +61,6 @@ class LuaMainTask : public Task {
virtual void Do();
Lua L;
TQueue<LuaExecCell> m_queue;
- volatile bool m_stopping;
friend class LuaExecCell;
};
diff --git a/src/LuaTask.cc b/src/LuaTask.cc
index 80a56f6..e1c722d 100644
--- a/src/LuaTask.cc
+++ b/src/LuaTask.cc
@@ -1,12 +1,18 @@
#include "LuaTask.h"
#include "Main.h"
#include "TaskMan.h"
+#include "Printer.h"
-class LuaTaskDummy : public Balau::LuaExecCell {
+class LuaTaskStopper : public Balau::LuaExecCell {
virtual void run(Balau::Lua &) { }
};
-Balau::LuaMainTask::LuaMainTask() : m_stopping(false) {
+Balau::LuaExecCell::LuaExecCell() : m_detached(false) {
+ Printer::elog(E_TASK, "LuaExecCell created at %p", this);
+}
+
+Balau::LuaMainTask::LuaMainTask() {
+ Printer::elog(E_TASK, "LuaMainTask created at %p", this);
L.open_base();
L.open_table();
L.open_string();
@@ -21,21 +27,25 @@ Balau::LuaMainTask::~LuaMainTask() {
}
void Balau::LuaMainTask::exec(LuaExecCell * cell) {
+ Printer::elog(E_TASK, "LuaMainTask at %p is asked to queue Cell %p", this, cell);
m_queue.push(cell);
}
void Balau::LuaMainTask::stop() {
- Atomic::CmpXChgVal(&m_stopping, true, false);
- exec(new LuaTaskDummy());
+ Printer::elog(E_TASK, "LuaMainTask at %p asked to stop", this);
+ exec(new LuaTaskStopper());
}
void Balau::LuaMainTask::Do() {
- while (!m_stopping) {
+ for (;;) {
LuaExecCell * cell;
+ Printer::elog(E_TASK, "LuaMainTask at %p tries to pop an ExecCell", this);
while ((cell = m_queue.pop())) {
- if (dynamic_cast<LuaTaskDummy *>(cell)) {
+ Printer::elog(E_TASK, "LuaMainTask at %p popped %p", this, cell);
+ if (dynamic_cast<LuaTaskStopper *>(cell)) {
+ Printer::elog(E_TASK, "LuaMainTask at %p is stopping", this);
delete cell;
- break;
+ return;
}
TaskMan::createTask(new LuaTask(L.thread(), cell), this);
}