[PATCH 4/5] score: Make zombie registry observable
Sebastian Huber
sebastian.huber at embedded-brains.de
Mon Aug 16 11:15:30 UTC 2021
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 c4b6c941a4..45c0795d9c 100644
--- a/cpukit/include/rtems/score/threadimpl.h
+++ b/cpukit/include/rtems/score/threadimpl.h
@@ -47,6 +47,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
*/
diff --git a/cpukit/score/src/threadrestart.c b/cpukit/score/src/threadrestart.c
index 5b1d6ae5f1..2240d8f713 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 );
--
2.26.2
More information about the devel
mailing list