diff options
author | chai <chaifix@163.com> | 2019-03-27 22:18:14 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-03-27 22:18:14 +0800 |
commit | 69f7d1bd745ed5680b9bc4e3cfdd882ff2a5ad26 (patch) | |
tree | 729e563da8fea6cf8c5455f3afdb3c6ce0aecde4 /source/libs/asura-lib-utils/threading/thread_impl_win32.cpp | |
parent | 66c5fdc564dd892ed265132d6c1378dbe3cebcee (diff) |
+threading
Diffstat (limited to 'source/libs/asura-lib-utils/threading/thread_impl_win32.cpp')
-rw-r--r-- | source/libs/asura-lib-utils/threading/thread_impl_win32.cpp | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/source/libs/asura-lib-utils/threading/thread_impl_win32.cpp b/source/libs/asura-lib-utils/threading/thread_impl_win32.cpp index e69de29..fd1b066 100644 --- a/source/libs/asura-lib-utils/threading/thread_impl_win32.cpp +++ b/source/libs/asura-lib-utils/threading/thread_impl_win32.cpp @@ -0,0 +1,69 @@ +#include "thread_impl_win32.h" +#include "thread.h" + +namespace AsuraEngine +{ + namespace Threading + { + + static DWORD WINAPI _thread_win32_runner(LPVOID param) + { + Thread* thread = (Thread*)param; + thread->Execute(); + return 0; + } + + ThreadImplWin32::ThreadImplWin32() + { + } + + ThreadImplWin32::~ThreadImplWin32() + { + if (!mHandle) return; + ::CloseHandle(mHandle); + mHandle = 0; + } + + bool ThreadImplWin32::Start(Thread* thread, uint32 stacksize/*=0*/) + { + assert(!IsRunning()); + mHandle = ::CreateThread( + NULL + , stacksize + , _thread_win32_runner + , thread + , 0 /*е*/ + , NULL); + + return mHandle; + } + + void ThreadImplWin32::Join() + { + // ̵߳ȴ̷߳ + ::WaitForSingleObject(mHandle, INFINITE); + } + + void ThreadImplWin32::Kill() + { + ::TerminateThread(mHandle, FALSE); + } + + bool ThreadImplWin32::IsRunning() + { + if (mHandle) { + DWORD exitCode = 0; + // https://blog.csdn.net/yuanmeng567/article/details/19485719 + ::GetExitCodeThread(mHandle, &exitCode); + return exitCode == STILL_ACTIVE; + } + return false; + } + + bool ThreadImplWin32::IsCurrent() + { + return mHandle == ::GetCurrentThread(); + } + + } +}
\ No newline at end of file |