aboutsummaryrefslogtreecommitdiff
path: root/src/3rdParty/efsw/platform/win/ThreadImpl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdParty/efsw/platform/win/ThreadImpl.cpp')
-rwxr-xr-xsrc/3rdParty/efsw/platform/win/ThreadImpl.cpp56
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
9namespace efsw { namespace Platform {
10
11ThreadImpl::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
20ThreadImpl::~ThreadImpl() {
21 if ( mThread ) {
22 CloseHandle( mThread );
23 }
24}
25
26void 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
35void ThreadImpl::terminate() {
36 if ( mThread ) {
37 TerminateThread( mThread, 0 );
38 }
39}
40
41unsigned 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