diff options
| author | Li Jin <dragon-fly@qq.com> | 2025-04-09 17:40:13 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2025-04-09 17:40:13 +0800 |
| commit | 9750786a5c03b5ce3ea22b240d1b3cd34990856b (patch) | |
| tree | e495e43245e1bacc86d33142af202613a82a40c1 /src/3rdParty/efsw/platform/posix/ThreadImpl.cpp | |
| parent | 571fb952b99e580a0381f539885f8f175e2ec3b0 (diff) | |
| download | yuescript-9750786a5c03b5ce3ea22b240d1b3cd34990856b.tar.gz yuescript-9750786a5c03b5ce3ea22b240d1b3cd34990856b.tar.bz2 yuescript-9750786a5c03b5ce3ea22b240d1b3cd34990856b.zip | |
Updated efsw. Fixed issue #204.
Diffstat (limited to 'src/3rdParty/efsw/platform/posix/ThreadImpl.cpp')
| -rw-r--r--[-rwxr-xr-x] | src/3rdParty/efsw/platform/posix/ThreadImpl.cpp | 17 |
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 | ||
| 10 | namespace efsw { namespace Platform { | 9 | namespace efsw { namespace Platform { |
| 11 | 10 | ||
| 12 | ThreadImpl::ThreadImpl( Thread* owner ) : mIsActive( false ) { | 11 | ThreadImpl::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 | ||
| 19 | ThreadImpl::~ThreadImpl() { | ||
| 20 | terminate(); | ||
| 21 | } | ||
| 22 | |||
| 20 | void ThreadImpl::wait() { | 23 | void 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 | ||
| 43 | void* ThreadImpl::entryPoint( void* userData ) { | 44 | void* 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 | ||
