diff options
author | Nicolas Noble <pixel@nobis-crew.org> | 2013-07-30 18:25:31 -0700 |
---|---|---|
committer | Nicolas Noble <pixel@nobis-crew.org> | 2013-07-30 18:25:31 -0700 |
commit | 1524f8eb8ca237ad8c02ae348cc8cb60276dbb15 (patch) | |
tree | 46e0ca2c8a45faaf1be48ab88170f852dcb2c627 /src/LuaTask.cc | |
parent | f4458b5600efe78b45db55459dfe49539ddec64f (diff) |
Saving some memory by having the LuaTasks being stackless when possible.
Diffstat (limited to 'src/LuaTask.cc')
-rw-r--r-- | src/LuaTask.cc | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/src/LuaTask.cc b/src/LuaTask.cc index 5075c36..30fdef2 100644 --- a/src/LuaTask.cc +++ b/src/LuaTask.cc @@ -42,18 +42,22 @@ void Balau::LuaMainTask::stop() { } void Balau::LuaMainTask::Do() { + LuaExecCell * cell = NULL; for (;;) { - LuaExecCell * cell; 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); + try { + cell = m_queue.pop(); + } + catch (Balau::EAgain & e) { + taskSwitch(); + } + 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); } } |