From 9750786a5c03b5ce3ea22b240d1b3cd34990856b Mon Sep 17 00:00:00 2001 From: Li Jin Date: Wed, 9 Apr 2025 17:40:13 +0800 Subject: Updated efsw. Fixed issue #204. --- src/3rdParty/efsw/platform/posix/ThreadImpl.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) mode change 100755 => 100644 src/3rdParty/efsw/platform/posix/ThreadImpl.cpp (limited to 'src/3rdParty/efsw/platform/posix/ThreadImpl.cpp') diff --git a/src/3rdParty/efsw/platform/posix/ThreadImpl.cpp b/src/3rdParty/efsw/platform/posix/ThreadImpl.cpp old mode 100755 new mode 100644 index e0ae84f..772fbc9 --- a/src/3rdParty/efsw/platform/posix/ThreadImpl.cpp +++ b/src/3rdParty/efsw/platform/posix/ThreadImpl.cpp @@ -5,11 +5,10 @@ #include #include -#include namespace efsw { namespace Platform { -ThreadImpl::ThreadImpl( Thread* owner ) : mIsActive( false ) { +ThreadImpl::ThreadImpl( efsw::Thread* owner ) : mIsActive( false ) { mIsActive = pthread_create( &mThread, NULL, &ThreadImpl::entryPoint, owner ) == 0; if ( !mIsActive ) { @@ -17,14 +16,16 @@ ThreadImpl::ThreadImpl( Thread* owner ) : mIsActive( false ) { } } +ThreadImpl::~ThreadImpl() { + terminate(); +} + void ThreadImpl::wait() { // Wait for the thread to finish, no timeout if ( mIsActive ) { assert( pthread_equal( pthread_self(), mThread ) == 0 ); - pthread_join( mThread, NULL ); - - mIsActive = false; // Reset the thread state + mIsActive = pthread_join( mThread, NULL ) != 0; } } @@ -41,14 +42,14 @@ void ThreadImpl::terminate() { } void* ThreadImpl::entryPoint( void* userData ) { - // The Thread instance is stored in the user data - Thread* owner = static_cast( userData ); - // Tell the thread to handle cancel requests immediatly #ifdef PTHREAD_CANCEL_ASYNCHRONOUS pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS, NULL ); #endif + // The Thread instance is stored in the user data + Thread* owner = static_cast( userData ); + // Forward to the owner owner->run(); -- cgit v1.2.3-55-g6feb