diff options
Diffstat (limited to 'src/LuaTask.cc')
-rw-r--r-- | src/LuaTask.cc | 58 |
1 files changed, 47 insertions, 11 deletions
diff --git a/src/LuaTask.cc b/src/LuaTask.cc index d722847..7e0b256 100644 --- a/src/LuaTask.cc +++ b/src/LuaTask.cc @@ -1,26 +1,58 @@ #include "LuaTask.h" #include "Main.h" #include "TaskMan.h" +#include "Printer.h" + +namespace { + +class LuaTaskStopper : public Balau::LuaExecCell { + virtual void run(Balau::Lua &) { } +}; + +}; + +Balau::LuaExecCell::LuaExecCell() { + 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(); + L.open_math(); + L.open_debug(); + L.open_bit(); + L.open_jit(); +} + +Balau::LuaMainTask::~LuaMainTask() { + L.close(); +} 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); - m_queueEvent.trigger(); } void Balau::LuaMainTask::stop() { - Atomic::CmpXChgVal(&m_stopping, true, false); - m_queueEvent.trigger(); + Printer::elog(E_TASK, "LuaMainTask at %p asked to stop", this); + exec(new LuaTaskStopper()); } void Balau::LuaMainTask::Do() { - while (!m_stopping) { - waitFor(&m_queueEvent); - + for (;;) { LuaExecCell * cell; - while ((cell = m_queue.pop(false))) - createTask(new LuaTask(L.thread(), cell), this); - - yield(); + Printer::elog(E_TASK, "LuaMainTask at %p tries to pop an ExecCell", this); + while ((cell = m_queue.pop())) { + 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; + return; + } + TaskMan::registerTask(new LuaTask(L.thread(), cell), this); + } } } @@ -37,9 +69,13 @@ void Balau::LuaExecCell::exec(LuaMainTask * mainTask) { Task::prepare(&m_event); mainTask->exec(this); if (!m_detached) - Task::yield(&m_event); + Task::operationYield(&m_event); } void Balau::LuaExecString::run(Lua & L) { L.load(m_str); } + +void Balau::LuaExecFile::run(Lua & L) { + L.load(m_file); +} |