From f4c338c63f3456a8eccd56c35e233843687d55be Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 29 Mar 2019 00:43:25 +0800 Subject: *thread --- source/libs/asura-lib-utils/threading/thread.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'source/libs/asura-lib-utils/threading/thread.cpp') diff --git a/source/libs/asura-lib-utils/threading/thread.cpp b/source/libs/asura-lib-utils/threading/thread.cpp index 51738de..9c71ace 100644 --- a/source/libs/asura-lib-utils/threading/thread.cpp +++ b/source/libs/asura-lib-utils/threading/thread.cpp @@ -13,9 +13,6 @@ namespace AsuraEngine Thread::Thread(Luax::LuaxState& father, const std::string& name) : mName(name) { - mState = lua_newthread(father); - SetLuaxMemberRef(father, mStateRef, -1); - lua_pop(father, 1); // mState } Thread::~Thread() @@ -79,13 +76,18 @@ namespace AsuraEngine return mName; } - void Thread::Execute() + void Thread::Process() { + LUAX_STATE(AEScripting::LuaEnv::Get()->GetMainState()); while (!mTaskQueue.empty()) { Task* task = mTaskQueue.front(); - if (task->Execute()) - task->Invoke(mState); + if (task && task->Execute()) + { + // unsafe + task->Invoke(); + this->LuaxRelease(state, task); + } mMutex.Lock(); mTaskQueue.pop(); -- cgit v1.1-26-g67d0