[rtems commit] score: Add _Thread_Exit()

Sebastian Huber sebh at rtems.org
Fri May 20 05:56:52 UTC 2016


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Thu May 12 06:12:06 2016 +0200

score: Add _Thread_Exit()

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,




More information about the vc mailing list