From a4634497c8ada51755249606d8dc4b4c2761c017 Mon Sep 17 00:00:00 2001 From: Pixel Date: Sun, 1 Apr 2012 12:41:16 -0700 Subject: Creating first pass on LuaTasks. --- src/LuaTask.cc | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/LuaTask.cc (limited to 'src/LuaTask.cc') diff --git a/src/LuaTask.cc b/src/LuaTask.cc new file mode 100644 index 0000000..754de6f --- /dev/null +++ b/src/LuaTask.cc @@ -0,0 +1,46 @@ +#include "LuaTask.h" +#include "Main.h" +#include "TaskMan.h" + +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(); +} + +void Balau::LuaMainTask::Do() { + while (!m_stopping) { + waitFor(&m_queueEvent); + + LuaExecCell * cell; + while ((cell = m_queue.pop(false))) { + createTask(new LuaTask(L.thread(), cell)); + } + + yield(); + } +} + +void Balau::LuaTask::Do() { + m_cell->run(L); + if (m_cell->m_detached) + delete m_cell; + else + m_cell->m_event.trigger(); +} + +void Balau::LuaExecCell::exec(LuaMainTask * mainTask) { + if (!m_detached) + Task::prepare(&m_event); + mainTask->exec(this); + if (!m_detached) + Task::yield(&m_event); +} + +void Balau::LuaExecString::run(Lua & L) { + L.load(m_str); +} -- cgit v1.2.3