From 3cef3198a560d2c9e16afb81f97e05bdc6f13a01 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Mon, 17 May 2021 14:46:02 +0200 Subject: score: Simplify calling _Thread_Exit() Move common code into _Thread_Exit(). This enables a tail call optimization in most cases. --- cpukit/posix/src/cancel.c | 12 ++++++------ cpukit/posix/src/pthreadexit.c | 11 +---------- 2 files changed, 7 insertions(+), 16 deletions(-) (limited to 'cpukit/posix/src') diff --git a/cpukit/posix/src/cancel.c b/cpukit/posix/src/cancel.c index 4756f10389..f2636e6a97 100644 --- a/cpukit/posix/src/cancel.c +++ b/cpukit/posix/src/cancel.c @@ -52,17 +52,17 @@ int pthread_cancel( pthread_t thread ) return ESRCH; } - cpu_self = _Thread_Dispatch_disable_critical( &lock_context ); - _ISR_lock_ISR_enable( &lock_context ); - + cpu_self = _Per_CPU_Get(); executing = _Per_CPU_Get_executing( cpu_self ); if ( the_thread == executing ) { - _Thread_Exit( executing, THREAD_LIFE_TERMINATING, PTHREAD_CANCELED ); + _ISR_lock_ISR_enable( &lock_context ); + _Thread_Exit( PTHREAD_CANCELED, THREAD_LIFE_TERMINATING ); } else { + _Thread_Dispatch_disable_with_CPU( cpu_self, &lock_context ); + _ISR_lock_ISR_enable( &lock_context ); _Thread_Cancel( the_thread, executing, PTHREAD_CANCELED ); + _Thread_Dispatch_enable( cpu_self ); } - - _Thread_Dispatch_enable( cpu_self ); return 0; } diff --git a/cpukit/posix/src/pthreadexit.c b/cpukit/posix/src/pthreadexit.c index 657497010b..d5b53bb45f 100644 --- a/cpukit/posix/src/pthreadexit.c +++ b/cpukit/posix/src/pthreadexit.c @@ -27,14 +27,5 @@ void pthread_exit( void *value_ptr ) { - Thread_Control *executing; - Per_CPU_Control *cpu_self; - - cpu_self = _Thread_Dispatch_disable(); - executing = _Per_CPU_Get_executing( cpu_self ); - - _Thread_Exit( executing, THREAD_LIFE_TERMINATING, value_ptr ); - - _Thread_Dispatch_direct_no_return( cpu_self ); - RTEMS_UNREACHABLE(); + _Thread_Exit( value_ptr, THREAD_LIFE_TERMINATING ); } -- cgit v1.2.3