[PATCH 03/32] score: Add _Thread_Exit()

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


The goal is to make _Thread_Exit() a no-return function in follow up
patches.

Update #2555.
Update #2626.
---
 cpukit/posix/src/pthreadexit.c                |  9 ++++++++-
 cpukit/rtems/src/taskdelete.c                 |  9 ++++++++-
 cpukit/score/include/rtems/score/threadimpl.h |  2 ++
 cpukit/score/src/threadrestart.c              | 18 ++++++++++++++----
 4 files changed, 32 insertions(+), 6 deletions(-)

diff --git a/cpukit/posix/src/pthreadexit.c b/cpukit/posix/src/pthreadexit.c
index e2ae806..940fa38 100644
--- a/cpukit/posix/src/pthreadexit.c
+++ b/cpukit/posix/src/pthreadexit.c
@@ -31,6 +31,7 @@ void _POSIX_Thread_Exit(
   void           *value_ptr
 )
 {
+  Thread_Control    *executing;
   Thread_Control    *unblocked;
   POSIX_API_Control *api;
   bool               previous_life_protection;
@@ -61,10 +62,16 @@ void _POSIX_Thread_Exit(
     }
   }
 
+  executing = _Thread_Executing;
+
   /*
    *  Now shut down the thread
    */
-  _Thread_Close( the_thread, _Thread_Executing );
+  if ( the_thread == executing ) {
+    _Thread_Exit( executing );
+  } else {
+    _Thread_Close( the_thread, executing );
+  }
 
   _Thread_Enable_dispatch();
   _Thread_Set_life_protection( previous_life_protection );
diff --git a/cpukit/rtems/src/taskdelete.c b/cpukit/rtems/src/taskdelete.c
index 7a06c51..c0d46d8 100644
--- a/cpukit/rtems/src/taskdelete.c
+++ b/cpukit/rtems/src/taskdelete.c
@@ -28,6 +28,7 @@ rtems_status_code rtems_task_delete(
 )
 {
   Thread_Control    *the_thread;
+  Thread_Control    *executing;
   Objects_Locations  location;
   bool               previous_life_protection;
 
@@ -50,7 +51,13 @@ rtems_status_code rtems_task_delete(
         }
       #endif
 
-      _Thread_Close( the_thread, _Thread_Executing );
+      executing = _Thread_Executing;
+
+      if ( the_thread == executing ) {
+        _Thread_Exit( executing );
+      } else {
+        _Thread_Close( the_thread, executing );
+      }
 
       _Objects_Put( &the_thread->Object );
       _Thread_Set_life_protection( previous_life_protection );
diff --git a/cpukit/score/include/rtems/score/threadimpl.h b/cpukit/score/include/rtems/score/threadimpl.h
index 3fdc2e8..be2095e 100644
--- a/cpukit/score/include/rtems/score/threadimpl.h
+++ b/cpukit/score/include/rtems/score/threadimpl.h
@@ -211,6 +211,8 @@ bool _Thread_Set_life_protection( bool protect );
  */
 void _Thread_Kill_zombies( void );
 
+void _Thread_Exit( Thread_Control *executing );
+
 /**
  * @brief Closes the thread.
  *
diff --git a/cpukit/score/src/threadrestart.c b/cpukit/score/src/threadrestart.c
index ca054fa..0184fd1 100644
--- a/cpukit/score/src/threadrestart.c
+++ b/cpukit/score/src/threadrestart.c
@@ -341,14 +341,12 @@ static void _Thread_Request_life_change(
 void _Thread_Close( Thread_Control *the_thread, Thread_Control *executing )
 {
   _Assert( _Thread_Is_life_protected( executing->Life.state ) );
+  _Assert( the_thread != executing );
 
   if ( _States_Is_dormant( the_thread->current_state ) ) {
     _Thread_Make_zombie( the_thread );
   } else {
-    if (
-      the_thread != executing
-        && !_Thread_Is_life_terminating( executing->Life.state )
-    ) {
+    if ( !_Thread_Is_life_terminating( executing->Life.state ) ) {
       /*
        * Wait for termination of victim thread.  If the executing thread is
        * also terminated, then do not wait.  This avoids potential cyclic
@@ -367,6 +365,18 @@ void _Thread_Close( Thread_Control *the_thread, Thread_Control *executing )
   }
 }
 
+void _Thread_Exit( Thread_Control *executing )
+{
+  _Assert( _Thread_Is_life_protected( executing->Life.state ) );
+
+  _Thread_Request_life_change(
+    executing,
+    executing,
+    executing->current_priority,
+    THREAD_LIFE_TERMINATING
+  );
+}
+
 bool _Thread_Restart(
   Thread_Control                 *the_thread,
   Thread_Control                 *executing,
-- 
1.8.4.5




More information about the devel mailing list