From 3bced067a4144381e59ce4bd0eb749eeff5ad1f4 Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 28 Mar 2019 08:56:15 +0800 Subject: *misc --- source/libs/asura-lib-utils/threading/thread.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 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 d1b055d..51738de 100644 --- a/source/libs/asura-lib-utils/threading/thread.cpp +++ b/source/libs/asura-lib-utils/threading/thread.cpp @@ -10,9 +10,12 @@ namespace AsuraEngine namespace Threading { - Thread::Thread(const std::string& name) + 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() @@ -31,8 +34,9 @@ namespace AsuraEngine } \ } - bool Thread::AddTask(ThreadTask* task) + bool Thread::AddTask(Task* task) { + lock(mMutex); mTaskQueue.push(task); return true; } @@ -43,30 +47,30 @@ namespace AsuraEngine try_start_thread(ThreadImplWin32); #endif - assert(mImpl); + ASSERT(mImpl); } void Thread::Join() { - assert(mImpl); + ASSERT(mImpl); mImpl->Join(); } void Thread::Kill() { - assert(mImpl); + ASSERT(mImpl); mImpl->Kill(); } bool Thread::IsRunning() { - assert(mImpl); + ASSERT(mImpl); return mImpl->IsRunning(); } bool Thread::IsCurrent() { - assert(mImpl); + ASSERT(mImpl); return mImpl->IsCurrent(); } @@ -79,9 +83,9 @@ namespace AsuraEngine { while (!mTaskQueue.empty()) { - ThreadTask* task = mTaskQueue.front(); + Task* task = mTaskQueue.front(); if (task->Execute()) - task->Invoke(); + task->Invoke(mState); mMutex.Lock(); mTaskQueue.pop(); -- cgit v1.1-26-g67d0