aboutsummaryrefslogtreecommitdiff
path: root/src/3rdParty/efsw/platform/posix/ThreadImpl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdParty/efsw/platform/posix/ThreadImpl.cpp')
-rw-r--r--[-rwxr-xr-x]src/3rdParty/efsw/platform/posix/ThreadImpl.cpp17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/3rdParty/efsw/platform/posix/ThreadImpl.cpp b/src/3rdParty/efsw/platform/posix/ThreadImpl.cpp
index e0ae84f..772fbc9 100755..100644
--- a/src/3rdParty/efsw/platform/posix/ThreadImpl.cpp
+++ b/src/3rdParty/efsw/platform/posix/ThreadImpl.cpp
@@ -5,11 +5,10 @@
5 5
6#include <cassert> 6#include <cassert>
7#include <efsw/Debug.hpp> 7#include <efsw/Debug.hpp>
8#include <iostream>
9 8
10namespace efsw { namespace Platform { 9namespace efsw { namespace Platform {
11 10
12ThreadImpl::ThreadImpl( Thread* owner ) : mIsActive( false ) { 11ThreadImpl::ThreadImpl( efsw::Thread* owner ) : mIsActive( false ) {
13 mIsActive = pthread_create( &mThread, NULL, &ThreadImpl::entryPoint, owner ) == 0; 12 mIsActive = pthread_create( &mThread, NULL, &ThreadImpl::entryPoint, owner ) == 0;
14 13
15 if ( !mIsActive ) { 14 if ( !mIsActive ) {
@@ -17,14 +16,16 @@ ThreadImpl::ThreadImpl( Thread* owner ) : mIsActive( false ) {
17 } 16 }
18} 17}
19 18
19ThreadImpl::~ThreadImpl() {
20 terminate();
21}
22
20void ThreadImpl::wait() { 23void ThreadImpl::wait() {
21 // Wait for the thread to finish, no timeout 24 // Wait for the thread to finish, no timeout
22 if ( mIsActive ) { 25 if ( mIsActive ) {
23 assert( pthread_equal( pthread_self(), mThread ) == 0 ); 26 assert( pthread_equal( pthread_self(), mThread ) == 0 );
24 27
25 pthread_join( mThread, NULL ); 28 mIsActive = pthread_join( mThread, NULL ) != 0;
26
27 mIsActive = false; // Reset the thread state
28 } 29 }
29} 30}
30 31
@@ -41,14 +42,14 @@ void ThreadImpl::terminate() {
41} 42}
42 43
43void* ThreadImpl::entryPoint( void* userData ) { 44void* ThreadImpl::entryPoint( void* userData ) {
44 // The Thread instance is stored in the user data
45 Thread* owner = static_cast<Thread*>( userData );
46
47// Tell the thread to handle cancel requests immediatly 45// Tell the thread to handle cancel requests immediatly
48#ifdef PTHREAD_CANCEL_ASYNCHRONOUS 46#ifdef PTHREAD_CANCEL_ASYNCHRONOUS
49 pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS, NULL ); 47 pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS, NULL );
50#endif 48#endif
51 49
50 // The Thread instance is stored in the user data
51 Thread* owner = static_cast<Thread*>( userData );
52
52 // Forward to the owner 53 // Forward to the owner
53 owner->run(); 54 owner->run();
54 55