score: Simplify calling _Thread_Exit()

Move common code into _Thread_Exit().  This enables a tail call
optimization in most cases.
This commit is contained in:
Sebastian Huber
2021-05-17 14:46:02 +02:00
parent b81d1ffd23
commit 3cef3198a5
6 changed files with 28 additions and 53 deletions

View File

@@ -339,14 +339,13 @@ void _Thread_Kill_zombies( void );
/** /**
* @brief Exits the currently executing thread. * @brief Exits the currently executing thread.
* *
* @param[in, out] executing The currently executing thread. * @param exit_value is the exit value of the thread.
* @param life_states_to_set The states to set. *
* @param[out] exit_value Contains the exit value of the thread. * @param life_states_to_set are the thread life states to set.
*/ */
void _Thread_Exit( RTEMS_NO_RETURN void _Thread_Exit(
Thread_Control *executing, void *exit_value,
Thread_Life_state life_states_to_set, Thread_Life_state life_states_to_set
void *exit_value
); );
/** /**

View File

@@ -52,17 +52,17 @@ int pthread_cancel( pthread_t thread )
return ESRCH; return ESRCH;
} }
cpu_self = _Thread_Dispatch_disable_critical( &lock_context ); cpu_self = _Per_CPU_Get();
_ISR_lock_ISR_enable( &lock_context );
executing = _Per_CPU_Get_executing( cpu_self ); executing = _Per_CPU_Get_executing( cpu_self );
if ( the_thread == executing ) { 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 { } else {
_Thread_Dispatch_disable_with_CPU( cpu_self, &lock_context );
_ISR_lock_ISR_enable( &lock_context );
_Thread_Cancel( the_thread, executing, PTHREAD_CANCELED ); _Thread_Cancel( the_thread, executing, PTHREAD_CANCELED );
_Thread_Dispatch_enable( cpu_self );
} }
_Thread_Dispatch_enable( cpu_self );
return 0; return 0;
} }

View File

@@ -27,14 +27,5 @@
void pthread_exit( void *value_ptr ) void pthread_exit( void *value_ptr )
{ {
Thread_Control *executing; _Thread_Exit( value_ptr, THREAD_LIFE_TERMINATING );
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();
} }

View File

@@ -55,23 +55,13 @@ rtems_status_code rtems_task_delete(
executing = _Per_CPU_Get_executing( cpu_self ); executing = _Per_CPU_Get_executing( cpu_self );
if ( the_thread == executing ) { if ( the_thread == executing ) {
_Thread_Dispatch_disable_with_CPU(
cpu_self,
&context.Base.Lock_context.Lock_context
);
_ISR_lock_ISR_enable( &context.Base.Lock_context.Lock_context ); _ISR_lock_ISR_enable( &context.Base.Lock_context.Lock_context );
/* /*
* The Classic tasks are neither detached nor joinable. In case of * The Classic tasks are neither detached nor joinable. In case of
* self deletion, they are detached, otherwise joinable by default. * self deletion, they are detached, otherwise joinable by default.
*/ */
_Thread_Exit( _Thread_Exit( NULL, THREAD_LIFE_TERMINATING | THREAD_LIFE_DETACHED );
executing,
THREAD_LIFE_TERMINATING | THREAD_LIFE_DETACHED,
NULL
);
_Thread_Dispatch_direct_no_return( cpu_self );
RTEMS_UNREACHABLE();
} else { } else {
_Thread_Close( the_thread, executing, &context ); _Thread_Close( the_thread, executing, &context );
} }

View File

@@ -30,18 +30,5 @@
void rtems_task_exit( void ) void rtems_task_exit( void )
{ {
Thread_Control *executing; _Thread_Exit( NULL, THREAD_LIFE_TERMINATING | THREAD_LIFE_DETACHED );
Per_CPU_Control *cpu_self;
cpu_self = _Thread_Dispatch_disable();
executing = _Per_CPU_Get_executing( cpu_self );
_Thread_Exit(
executing,
THREAD_LIFE_TERMINATING | THREAD_LIFE_DETACHED,
NULL
);
_Thread_Dispatch_direct_no_return( cpu_self );
RTEMS_UNREACHABLE();
} }

View File

@@ -489,14 +489,19 @@ void _Thread_Close(
); );
} }
void _Thread_Exit( RTEMS_NO_RETURN void _Thread_Exit(
Thread_Control *executing, void *exit_value,
Thread_Life_state life_states_to_set, Thread_Life_state life_states_to_set
void *exit_value
) )
{ {
Per_CPU_Control *cpu_self;
Thread_Control *executing;
ISR_lock_Context lock_context; ISR_lock_Context lock_context;
_ISR_lock_ISR_disable( &lock_context );
cpu_self = _Thread_Dispatch_disable_critical( &lock_context );
executing = _Per_CPU_Get_executing( cpu_self );
_Assert( _Assert(
_Watchdog_Get_state( &executing->Timer.Watchdog ) == WATCHDOG_INACTIVE _Watchdog_Get_state( &executing->Timer.Watchdog ) == WATCHDOG_INACTIVE
); );
@@ -505,7 +510,7 @@ void _Thread_Exit(
|| executing->current_state == STATES_SUSPENDED || executing->current_state == STATES_SUSPENDED
); );
_Thread_State_acquire( executing, &lock_context ); _Thread_State_acquire_critical( executing, &lock_context );
_Thread_Set_exit_value( executing, exit_value ); _Thread_Set_exit_value( executing, exit_value );
_Thread_Change_life_locked( _Thread_Change_life_locked(
executing, executing,
@@ -514,6 +519,9 @@ void _Thread_Exit(
THREAD_LIFE_PROTECTED | THREAD_LIFE_CHANGE_DEFERRED THREAD_LIFE_PROTECTED | THREAD_LIFE_CHANGE_DEFERRED
); );
_Thread_State_release( executing, &lock_context ); _Thread_State_release( executing, &lock_context );
_Thread_Dispatch_direct_no_return( cpu_self );
RTEMS_UNREACHABLE();
} }
Status_Control _Thread_Restart( Status_Control _Thread_Restart(