[PATCH] score: Use PTHREAD_CANCELED for _Thread_Cancel()

Sebastian Huber sebastian.huber at embedded-brains.de
Tue Jul 19 08:51:55 UTC 2022


The rtems_task_delete() directive is basically just a combined pthread_cancel()
and pthread_join().  In addition, it removes the PTHREAD_DETACHED state.  The
exit value returned by pthread_join() of threads cancelled by
rtems_task_delete() should reflect this by getting a PTHREAD_CANCELED value and
instead of NULL.

Close #4680.
---
 cpukit/include/rtems/score/threadimpl.h |  5 +----
 cpukit/posix/src/cancel.c               |  2 +-
 cpukit/score/src/threadrestart.c        | 10 +++++-----
 testsuites/psxtests/psx08/init.c        |  2 +-
 4 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/cpukit/include/rtems/score/threadimpl.h b/cpukit/include/rtems/score/threadimpl.h
index e6e77b195c..638815237f 100644
--- a/cpukit/include/rtems/score/threadimpl.h
+++ b/cpukit/include/rtems/score/threadimpl.h
@@ -429,14 +429,11 @@ typedef enum {
 
  * @param[in, out] life_states_to_clear is the set of thread life states to
  *   clear for the thread to cancel.
-
- * @param exit_value is the exit value for the thread to cancel.
  */
 Thread_Cancel_state _Thread_Cancel(
   Thread_Control   *the_thread,
   Thread_Control   *executing,
-  Thread_Life_state life_states_to_clear,
-  void             *exit_value
+  Thread_Life_state life_states_to_clear
 );
 
 /**
diff --git a/cpukit/posix/src/cancel.c b/cpukit/posix/src/cancel.c
index 0fb2199f0a..1ccfe75b0b 100644
--- a/cpukit/posix/src/cancel.c
+++ b/cpukit/posix/src/cancel.c
@@ -75,7 +75,7 @@ int pthread_cancel( pthread_t thread )
   } else {
     _Thread_Dispatch_disable_with_CPU( cpu_self, &lock_context );
     _ISR_lock_ISR_enable( &lock_context );
-    (void) _Thread_Cancel( the_thread, executing, 0, PTHREAD_CANCELED );
+    (void) _Thread_Cancel( the_thread, executing, 0 );
     _Thread_Dispatch_enable( cpu_self );
   }
   return 0;
diff --git a/cpukit/score/src/threadrestart.c b/cpukit/score/src/threadrestart.c
index e1911beb2b..584cfa5d8b 100644
--- a/cpukit/score/src/threadrestart.c
+++ b/cpukit/score/src/threadrestart.c
@@ -55,6 +55,8 @@
 #include <rtems/score/userextimpl.h>
 #include <rtems/score/watchdogimpl.h>
 
+#include <pthread.h>
+
 #define THREAD_JOIN_TQ_OPERATIONS &_Thread_queue_Operations_priority_inherit
 
 static void _Thread_Life_action_handler(
@@ -433,8 +435,7 @@ static void _Thread_Try_life_change_request(
 Thread_Cancel_state _Thread_Cancel(
   Thread_Control   *the_thread,
   Thread_Control   *executing,
-  Thread_Life_state life_states_to_clear,
-  void             *exit_value
+  Thread_Life_state life_states_to_clear
 )
 {
   ISR_lock_Context  lock_context;
@@ -444,7 +445,7 @@ Thread_Cancel_state _Thread_Cancel(
 
   _Thread_State_acquire( the_thread, &lock_context );
 
-  _Thread_Set_exit_value( the_thread, exit_value );
+  _Thread_Set_exit_value( the_thread, PTHREAD_CANCELED );
   previous = _Thread_Change_life_locked(
     the_thread,
     life_states_to_clear,
@@ -476,8 +477,7 @@ Status_Control _Thread_Close(
   );
   _ISR_lock_ISR_enable( &queue_context->Lock_context.Lock_context );
 
-  cancel_state =
-    _Thread_Cancel( the_thread, executing, THREAD_LIFE_DETACHED, NULL );
+  cancel_state = _Thread_Cancel( the_thread, executing, THREAD_LIFE_DETACHED );
 
   if ( cancel_state == THREAD_CANCEL_DONE ) {
     _Thread_Dispatch_enable( cpu_self );
diff --git a/testsuites/psxtests/psx08/init.c b/testsuites/psxtests/psx08/init.c
index 1caf9aa537..56124f4e23 100644
--- a/testsuites/psxtests/psx08/init.c
+++ b/testsuites/psxtests/psx08/init.c
@@ -144,7 +144,7 @@ static void test_delete_deadlock( void )
   value = NULL;
   eno = pthread_join( ctx.protected_join, &value );
   rtems_test_assert( eno == 0 );
-  rtems_test_assert( value == NULL );
+  rtems_test_assert( value == PTHREAD_CANCELED );
 
   rtems_test_assert( ctx.delete_status == RTEMS_INCORRECT_STATE );
 }
-- 
2.35.3



More information about the devel mailing list