[rtems commit] score: Make zombie registry observable

Sebastian Huber sebh at rtems.org
Wed Aug 18 11:37:08 UTC 2021


Module:    rtems
Branch:    master
Commit:    d433690591cb7ba7eaf03df524640b9fc0834f7e
Changeset: http://git.rtems.org/rtems/commit/?id=d433690591cb7ba7eaf03df524640b9fc0834f7e

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Aug 13 08:43:47 2021 +0200

score: Make zombie registry observable

This helps to write tests for _Thread_Wait_for_execution_stop().

Rename Thread_Zombie_control in Thread_Zombie_registry.

---

 cpukit/include/rtems/score/threadimpl.h | 27 +++++++++++++++++++++++++++
 cpukit/score/src/threadrestart.c        | 29 +++++++++++++----------------
 2 files changed, 40 insertions(+), 16 deletions(-)

diff --git a/cpukit/include/rtems/score/threadimpl.h b/cpukit/include/rtems/score/threadimpl.h
index c4b6c94..45c0795 100644
--- a/cpukit/include/rtems/score/threadimpl.h
+++ b/cpukit/include/rtems/score/threadimpl.h
@@ -48,6 +48,33 @@ extern "C" {
  */
 
 /**
+ * @brief The thread zombie registry is used to register threads in the
+ *   #STATES_ZOMBIE state.
+ */
+typedef struct {
+#if defined(RTEMS_SMP)
+  /**
+   * @brief This lock protects the zombie chain.
+   */
+  ISR_lock_Control Lock;
+#endif
+
+  /**
+   * @brief This chain contains the registered zombie threads.
+   */
+  Chain_Control Chain;
+} Thread_Zombie_registry;
+
+/**
+ * @brief This object is a registry for threads in the #STATES_ZOMBIE state.
+ *
+ * The registry contains zombie threads waiting to get killed by
+ * _Thread_Kill_zombies().  Use _Thread_Add_to_zombie_registry() to add zombie
+ * threads to the registry.
+ */
+extern Thread_Zombie_registry _Thread_Zombies;
+
+/**
  *  Self for the GNU Ada Run-Time
  */
 extern void *rtems_ada_self;
diff --git a/cpukit/score/src/threadrestart.c b/cpukit/score/src/threadrestart.c
index 5b1d6ae..2240d8f 100644
--- a/cpukit/score/src/threadrestart.c
+++ b/cpukit/score/src/threadrestart.c
@@ -44,14 +44,11 @@ static void _Thread_Life_action_handler(
   ISR_lock_Context *lock_context
 );
 
-typedef struct {
-  Chain_Control Chain;
-  ISR_lock_Control Lock;
-} Thread_Zombie_control;
-
-static Thread_Zombie_control _Thread_Zombies = {
-  .Chain = CHAIN_INITIALIZER_EMPTY( _Thread_Zombies.Chain ),
-  .Lock = ISR_LOCK_INITIALIZER( "thread zombies" )
+Thread_Zombie_registry _Thread_Zombies = {
+#if defined(RTEMS_SMP)
+  .Lock = ISR_LOCK_INITIALIZER( "Thread Zombies" ),
+#endif
+  .Chain = CHAIN_INITIALIZER_EMPTY( _Thread_Zombies.Chain )
 };
 
 static void _Thread_Raise_real_priority(
@@ -115,10 +112,10 @@ static void _Thread_Wake_up_joining_threads( Thread_Control *the_thread )
   );
 }
 
-static void _Thread_Add_to_zombie_chain( Thread_Control *the_thread )
+static void _Thread_Add_to_zombie_registry( Thread_Control *the_thread )
 {
-  ISR_lock_Context       lock_context;
-  Thread_Zombie_control *zombies;
+  ISR_lock_Context        lock_context;
+  Thread_Zombie_registry *zombies;
 
   zombies = &_Thread_Zombies;
   _ISR_lock_ISR_disable_and_acquire( &zombies->Lock, &lock_context );
@@ -148,7 +145,7 @@ static void _Thread_Make_zombie( Thread_Control *the_thread )
    * threads, so that they are able to clean up the thread immediately.  This
    * matters for SMP configurations.
    */
-  _Thread_Add_to_zombie_chain( the_thread );
+  _Thread_Add_to_zombie_registry( the_thread );
 
   _Thread_Wake_up_joining_threads( the_thread );
 }
@@ -169,16 +166,16 @@ static void _Thread_Wait_for_execution_stop( const Thread_Control *the_thread )
 #endif
 }
 
-static Thread_Control *_Thread_Get_zombie( Thread_Zombie_control *zombies )
+static Thread_Control *_Thread_Get_zombie( Thread_Zombie_registry *zombies )
 {
   return (Thread_Control *) _Chain_Get_unprotected( &zombies->Chain );
 }
 
 void _Thread_Kill_zombies( void )
 {
-  ISR_lock_Context       lock_context;
-  Thread_Zombie_control *zombies;
-  Thread_Control        *the_thread;
+  ISR_lock_Context        lock_context;
+  Thread_Zombie_registry *zombies;
+  Thread_Control         *the_thread;
 
   zombies = &_Thread_Zombies;
   _ISR_lock_ISR_disable_and_acquire( &zombies->Lock, &lock_context );



More information about the vc mailing list