diff options
| author | Li Jin <dragon-fly@qq.com> | 2022-11-15 17:23:46 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2022-11-15 17:52:09 +0800 |
| commit | 94f8330613877b3582d32bd11abd83a97b4399ad (patch) | |
| tree | 5359de314be1ebde17f8d1e48632a97d18f9e50f /src/3rdParty/efsw/platform/win/ThreadImpl.cpp | |
| parent | 60f8f00a022ac08701792b2897b72d8c99b50f52 (diff) | |
| download | yuescript-94f8330613877b3582d32bd11abd83a97b4399ad.tar.gz yuescript-94f8330613877b3582d32bd11abd83a97b4399ad.tar.bz2 yuescript-94f8330613877b3582d32bd11abd83a97b4399ad.zip | |
adding -w option to Yuescript tool.
Diffstat (limited to 'src/3rdParty/efsw/platform/win/ThreadImpl.cpp')
| -rwxr-xr-x | src/3rdParty/efsw/platform/win/ThreadImpl.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/3rdParty/efsw/platform/win/ThreadImpl.cpp b/src/3rdParty/efsw/platform/win/ThreadImpl.cpp new file mode 100755 index 0000000..d0fde8b --- /dev/null +++ b/src/3rdParty/efsw/platform/win/ThreadImpl.cpp | |||
| @@ -0,0 +1,56 @@ | |||
| 1 | #include <assert.h> | ||
| 2 | #include <efsw/Thread.hpp> | ||
| 3 | #include <efsw/platform/win/ThreadImpl.hpp> | ||
| 4 | |||
| 5 | #if EFSW_PLATFORM == EFSW_PLATFORM_WIN32 | ||
| 6 | |||
| 7 | #include <efsw/Debug.hpp> | ||
| 8 | |||
| 9 | namespace efsw { namespace Platform { | ||
| 10 | |||
| 11 | ThreadImpl::ThreadImpl( Thread* owner ) { | ||
| 12 | mThread = reinterpret_cast<HANDLE>( | ||
| 13 | _beginthreadex( NULL, 0, &ThreadImpl::entryPoint, owner, 0, &mThreadId ) ); | ||
| 14 | |||
| 15 | if ( !mThread ) { | ||
| 16 | efDEBUG( "Failed to create thread\n" ); | ||
| 17 | } | ||
| 18 | } | ||
| 19 | |||
| 20 | ThreadImpl::~ThreadImpl() { | ||
| 21 | if ( mThread ) { | ||
| 22 | CloseHandle( mThread ); | ||
| 23 | } | ||
| 24 | } | ||
| 25 | |||
| 26 | void ThreadImpl::wait() { | ||
| 27 | // Wait for the thread to finish, no timeout | ||
| 28 | if ( mThread ) { | ||
| 29 | assert( mThreadId != GetCurrentThreadId() ); // A thread cannot wait for itself! | ||
| 30 | |||
| 31 | WaitForSingleObject( mThread, INFINITE ); | ||
| 32 | } | ||
| 33 | } | ||
| 34 | |||
| 35 | void ThreadImpl::terminate() { | ||
| 36 | if ( mThread ) { | ||
| 37 | TerminateThread( mThread, 0 ); | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | unsigned int __stdcall ThreadImpl::entryPoint( void* userData ) { | ||
| 42 | // The Thread instance is stored in the user data | ||
| 43 | Thread* owner = static_cast<Thread*>( userData ); | ||
| 44 | |||
| 45 | // Forward to the owner | ||
| 46 | owner->run(); | ||
| 47 | |||
| 48 | // Optional, but it is cleaner | ||
| 49 | _endthreadex( 0 ); | ||
| 50 | |||
| 51 | return 0; | ||
| 52 | } | ||
| 53 | |||
| 54 | }} // namespace efsw::Platform | ||
| 55 | |||
| 56 | #endif | ||
