summaryrefslogtreecommitdiff
path: root/source/libs/asura-lib-utils/threading/thread.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2019-03-28 08:56:15 +0800
committerchai <chaifix@163.com>2019-03-28 08:56:15 +0800
commit3bced067a4144381e59ce4bd0eb749eeff5ad1f4 (patch)
tree0352c8ae263dae904967f9e21326ce2a4ca9ada8 /source/libs/asura-lib-utils/threading/thread.cpp
parentf6bcacef6e10200b1c0dc34c4aa34313cbfc0392 (diff)
*misc
Diffstat (limited to 'source/libs/asura-lib-utils/threading/thread.cpp')
-rw-r--r--source/libs/asura-lib-utils/threading/thread.cpp22
1 files changed, 13 insertions, 9 deletions
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();