forked from Imagelibrary/rtems
score: Simplify _Thread_Life_action_handler()
Use _Thread_Change_life_locked() to avoid duplicated code. Avoid Giant lock in _Thread_Life_action_handler(). Update #2555. Update #2626.
This commit is contained in:
@@ -523,7 +523,6 @@ typedef struct {
|
|||||||
* operations to manipulate and evaluate the thread life state.
|
* operations to manipulate and evaluate the thread life state.
|
||||||
*/
|
*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
THREAD_LIFE_NORMAL = 0x0,
|
|
||||||
THREAD_LIFE_PROTECTED = 0x1,
|
THREAD_LIFE_PROTECTED = 0x1,
|
||||||
THREAD_LIFE_RESTARTING = 0x2,
|
THREAD_LIFE_RESTARTING = 0x2,
|
||||||
THREAD_LIFE_TERMINATING = 0x4
|
THREAD_LIFE_TERMINATING = 0x4
|
||||||
|
|||||||
@@ -211,8 +211,6 @@ bool _Thread_Initialize(
|
|||||||
|
|
||||||
_Thread_Action_control_initialize( &the_thread->Post_switch_actions );
|
_Thread_Action_control_initialize( &the_thread->Post_switch_actions );
|
||||||
|
|
||||||
RTEMS_STATIC_ASSERT( THREAD_LIFE_NORMAL == 0, Life_state );
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Open the object
|
* Open the object
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -220,36 +220,6 @@ void _Thread_Kill_zombies( void )
|
|||||||
_ISR_lock_Release_and_ISR_enable( &zombies->Lock, &lock_context );
|
_ISR_lock_Release_and_ISR_enable( &zombies->Lock, &lock_context );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _Thread_Add_life_change_action(
|
|
||||||
Thread_Control *the_thread
|
|
||||||
)
|
|
||||||
{
|
|
||||||
ISR_lock_Context lock_context;
|
|
||||||
|
|
||||||
_Thread_State_acquire( the_thread, &lock_context );
|
|
||||||
_Thread_Add_post_switch_action(
|
|
||||||
the_thread,
|
|
||||||
&the_thread->Life.Action,
|
|
||||||
_Thread_Life_action_handler
|
|
||||||
);
|
|
||||||
_Thread_State_release( the_thread, &lock_context );
|
|
||||||
}
|
|
||||||
|
|
||||||
static void _Thread_Start_life_change_for_executing(
|
|
||||||
Thread_Control *executing
|
|
||||||
)
|
|
||||||
{
|
|
||||||
_Assert(
|
|
||||||
_Watchdog_Get_state( &executing->Timer.Watchdog ) == WATCHDOG_INACTIVE
|
|
||||||
);
|
|
||||||
_Assert(
|
|
||||||
executing->current_state == STATES_READY
|
|
||||||
|| executing->current_state == STATES_SUSPENDED
|
|
||||||
);
|
|
||||||
|
|
||||||
_Thread_Add_life_change_action( executing );
|
|
||||||
}
|
|
||||||
|
|
||||||
static Thread_Life_state _Thread_Change_life_locked(
|
static Thread_Life_state _Thread_Change_life_locked(
|
||||||
Thread_Control *the_thread,
|
Thread_Control *the_thread,
|
||||||
Thread_Life_state clear,
|
Thread_Life_state clear,
|
||||||
@@ -293,11 +263,12 @@ void _Thread_Life_action_handler(
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
Thread_Life_state previous_life_state;
|
Thread_Life_state previous_life_state;
|
||||||
|
Per_CPU_Control *cpu_self;
|
||||||
|
|
||||||
(void) action;
|
(void) action;
|
||||||
|
|
||||||
previous_life_state = executing->Life.state;
|
previous_life_state = executing->Life.state;
|
||||||
executing->Life.state = THREAD_LIFE_PROTECTED;
|
executing->Life.state = previous_life_state | THREAD_LIFE_PROTECTED;
|
||||||
|
|
||||||
_Thread_State_release( executing, lock_context );
|
_Thread_State_release( executing, lock_context );
|
||||||
|
|
||||||
@@ -309,20 +280,28 @@ void _Thread_Life_action_handler(
|
|||||||
_User_extensions_Thread_restart( executing );
|
_User_extensions_Thread_restart( executing );
|
||||||
}
|
}
|
||||||
|
|
||||||
_Thread_Disable_dispatch();
|
cpu_self = _Thread_Dispatch_disable();
|
||||||
|
|
||||||
if ( _Thread_Is_life_terminating( previous_life_state ) ) {
|
if ( _Thread_Is_life_terminating( previous_life_state ) ) {
|
||||||
_Thread_Make_zombie( executing );
|
_Thread_Make_zombie( executing );
|
||||||
|
|
||||||
_Thread_Enable_dispatch();
|
_Thread_Dispatch_enable( cpu_self );
|
||||||
RTEMS_UNREACHABLE();
|
RTEMS_UNREACHABLE();
|
||||||
} else {
|
}
|
||||||
|
|
||||||
_Assert( _Thread_Is_life_restarting( previous_life_state ) );
|
_Assert( _Thread_Is_life_restarting( previous_life_state ) );
|
||||||
|
|
||||||
if ( _Thread_Is_life_terminating( executing->Life.state ) ) {
|
_Thread_State_acquire( executing, lock_context );
|
||||||
/* Someone deleted us in the mean-time */
|
|
||||||
_Thread_Start_life_change_for_executing( executing );
|
_Thread_Change_life_locked(
|
||||||
} else {
|
executing,
|
||||||
|
THREAD_LIFE_PROTECTED | THREAD_LIFE_RESTARTING,
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
|
_Thread_State_release( executing, lock_context );
|
||||||
|
|
||||||
_Assert(
|
_Assert(
|
||||||
_Watchdog_Get_state( &executing->Timer.Watchdog ) == WATCHDOG_INACTIVE
|
_Watchdog_Get_state( &executing->Timer.Watchdog ) == WATCHDOG_INACTIVE
|
||||||
);
|
);
|
||||||
@@ -331,22 +310,9 @@ void _Thread_Life_action_handler(
|
|||||||
|| executing->current_state == STATES_SUSPENDED
|
|| executing->current_state == STATES_SUSPENDED
|
||||||
);
|
);
|
||||||
|
|
||||||
executing->Life.state = THREAD_LIFE_NORMAL;
|
|
||||||
|
|
||||||
_User_extensions_Destroy_iterators( executing );
|
_User_extensions_Destroy_iterators( executing );
|
||||||
_Thread_Load_environment( executing );
|
_Thread_Load_environment( executing );
|
||||||
|
|
||||||
#if defined(RTEMS_SMP)
|
|
||||||
{
|
|
||||||
ISR_Level level;
|
|
||||||
|
|
||||||
_Giant_Release( _Per_CPU_Get() );
|
|
||||||
|
|
||||||
_ISR_Disable_without_giant( level );
|
|
||||||
(void) level;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
|
#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
|
||||||
if ( executing->fp_context != NULL ) {
|
if ( executing->fp_context != NULL ) {
|
||||||
_Context_Restore_fp( &executing->fp_context );
|
_Context_Restore_fp( &executing->fp_context );
|
||||||
@@ -355,8 +321,6 @@ void _Thread_Life_action_handler(
|
|||||||
|
|
||||||
_Context_Restart_self( &executing->Registers );
|
_Context_Restart_self( &executing->Registers );
|
||||||
RTEMS_UNREACHABLE();
|
RTEMS_UNREACHABLE();
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _Thread_Add_life_change_request( Thread_Control *the_thread )
|
static void _Thread_Add_life_change_request( Thread_Control *the_thread )
|
||||||
|
|||||||
Reference in New Issue
Block a user