[PATCH 16/32] score: Simplify _Thread_Life_action_handler()

Sebastian Huber sebastian.huber at embedded-brains.de
Wed May 18 09:20:35 UTC 2016


Use _Thread_Change_life_locked() to avoid duplicated code.  Avoid Giant
lock in _Thread_Life_action_handler().

Update #2555.
Update #2626.
---
 cpukit/score/include/rtems/score/thread.h     |  1 -
 cpukit/score/include/rtems/score/threadimpl.h |  9 ---
 cpukit/score/src/threadinitialize.c           |  2 -
 cpukit/score/src/threadrestart.c              | 87 ++++++++++-----------------
 4 files changed, 31 insertions(+), 68 deletions(-)

diff --git a/cpukit/score/include/rtems/score/thread.h b/cpukit/score/include/rtems/score/thread.h
index ac68e0f..22e42bd 100644
--- a/cpukit/score/include/rtems/score/thread.h
+++ b/cpukit/score/include/rtems/score/thread.h
@@ -520,7 +520,6 @@ typedef struct {
  * changes triggered with thread restart and delete requests.
  */
 typedef enum {
-  THREAD_LIFE_NORMAL = 0x0,
   THREAD_LIFE_PROTECTED = 0x1,
   THREAD_LIFE_RESTARTING = 0x2,
   THREAD_LIFE_TERMINATING = 0x4
diff --git a/cpukit/score/include/rtems/score/threadimpl.h b/cpukit/score/include/rtems/score/threadimpl.h
index 0784b50..174f767 100644
--- a/cpukit/score/include/rtems/score/threadimpl.h
+++ b/cpukit/score/include/rtems/score/threadimpl.h
@@ -699,15 +699,6 @@ RTEMS_INLINE_ROUTINE void _Thread_Unblock (
 
 RTEMS_INLINE_ROUTINE void _Thread_Do_self_restart( Thread_Control *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 ( executing->fp_context != NULL )
     _Context_Restore_fp( &executing->fp_context );
diff --git a/cpukit/score/src/threadinitialize.c b/cpukit/score/src/threadinitialize.c
index 47d546e..229d68b 100644
--- a/cpukit/score/src/threadinitialize.c
+++ b/cpukit/score/src/threadinitialize.c
@@ -211,8 +211,6 @@ bool _Thread_Initialize(
 
   _Thread_Action_control_initialize( &the_thread->Post_switch_actions );
 
-  RTEMS_STATIC_ASSERT( THREAD_LIFE_NORMAL == 0, Life_state );
-
   /*
    *  Open the object
    */
diff --git a/cpukit/score/src/threadrestart.c b/cpukit/score/src/threadrestart.c
index c21544e..4dda28b 100644
--- a/cpukit/score/src/threadrestart.c
+++ b/cpukit/score/src/threadrestart.c
@@ -220,36 +220,6 @@ void _Thread_Kill_zombies( void )
   _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(
   Thread_Control    *the_thread,
   Thread_Life_state  clear,
@@ -292,12 +262,13 @@ void _Thread_Life_action_handler(
   ISR_lock_Context *lock_context
 )
 {
-  Thread_Life_state previous_life_state;
+  Thread_Life_state  previous_life_state;
+  Per_CPU_Control   *cpu_self;
 
   (void) action;
 
   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 );
 
@@ -309,36 +280,40 @@ void _Thread_Life_action_handler(
     _User_extensions_Thread_restart( executing );
   }
 
-  _Thread_Disable_dispatch();
+  cpu_self = _Thread_Dispatch_disable();
 
   if ( _Thread_Is_life_terminating( previous_life_state ) ) {
     _Thread_Make_zombie( executing );
 
-    _Thread_Enable_dispatch();
+    _Thread_Dispatch_enable( cpu_self );
     RTEMS_UNREACHABLE();
-  } else {
-    _Assert( _Thread_Is_life_restarting( previous_life_state ) );
-
-    if ( _Thread_Is_life_terminating( executing->Life.state ) ) {
-      /* Someone deleted us in the mean-time */
-      _Thread_Start_life_change_for_executing( executing );
-    } else {
-      _Assert(
-        _Watchdog_Get_state( &executing->Timer.Watchdog ) == WATCHDOG_INACTIVE
-      );
-      _Assert(
-        executing->current_state == STATES_READY
-          || executing->current_state == STATES_SUSPENDED
-      );
-
-      executing->Life.state = THREAD_LIFE_NORMAL;
-
-      _User_extensions_Destroy_iterators( executing );
-      _Thread_Load_environment( executing );
-      _Thread_Do_self_restart( executing );
-      RTEMS_UNREACHABLE();
-    }
   }
+
+  _Assert( _Thread_Is_life_restarting( previous_life_state ) );
+
+  _Thread_State_acquire( executing, lock_context );
+
+  _Thread_Change_life_locked(
+    executing,
+    THREAD_LIFE_PROTECTED | THREAD_LIFE_RESTARTING,
+    0,
+    0
+  );
+
+  _Thread_State_release( executing, lock_context );
+
+  _Assert(
+    _Watchdog_Get_state( &executing->Timer.Watchdog ) == WATCHDOG_INACTIVE
+  );
+  _Assert(
+    executing->current_state == STATES_READY
+      || executing->current_state == STATES_SUSPENDED
+  );
+
+  _User_extensions_Destroy_iterators( executing );
+  _Thread_Load_environment( executing );
+  _Thread_Do_self_restart( executing );
+  RTEMS_UNREACHABLE();
 }
 
 static void _Thread_Add_life_change_request( Thread_Control *the_thread )
-- 
1.8.4.5




More information about the devel mailing list