From b7c281e1d7c26d4414706d529862407d07e385c2 Mon Sep 17 00:00:00 2001 From: Pixel Date: Tue, 3 Apr 2012 16:05:07 -0700 Subject: Having a slightly better mechanism for stopping the LuaMainTask, as well as some debugging messages. --- src/LuaTask.cc | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'src/LuaTask.cc') 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(cell)) { + Printer::elog(E_TASK, "LuaMainTask at %p popped %p", this, cell); + if (dynamic_cast(cell)) { + Printer::elog(E_TASK, "LuaMainTask at %p is stopping", this); delete cell; - break; + return; } TaskMan::createTask(new LuaTask(L.thread(), cell), this); } -- cgit v1.2.3