[PATCH] Return status code for _Thread_Start()

Sebastian Huber sebastian.huber at embedded-brains.de
Mon Apr 26 11:54:47 UTC 2021


This avoids having conditional statements to get the API-specific status
code.
---
 cpukit/include/rtems/score/threadimpl.h | 7 +++----
 cpukit/posix/src/pthreadcreate.c        | 5 ++---
 cpukit/rtems/src/taskstart.c            | 7 ++++---
 cpukit/score/src/threadstart.c          | 6 +++---
 4 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/cpukit/include/rtems/score/threadimpl.h b/cpukit/include/rtems/score/threadimpl.h
index d9c0779b08..5dfd142b92 100644
--- a/cpukit/include/rtems/score/threadimpl.h
+++ b/cpukit/include/rtems/score/threadimpl.h
@@ -260,12 +260,11 @@ void _Thread_Free(
  * @param[in, out] is the ISR lock context which shall be used to disable the
  *   local interrupts before the call of this routine.
  *
- * @retval true The thread was in the dormant state and was sucessefully
- *   started.
+ * @retval STATUS_SUCCESSFUL The thread start was successful.
  *
- * @retval false Otherwise.
+ * @retval STATUS_INCORRECT_STATE The thread was already started.
  */
-bool _Thread_Start(
+Status_Control _Thread_Start(
   Thread_Control                 *the_thread,
   const Thread_Entry_information *entry,
   ISR_lock_Context               *lock_context
diff --git a/cpukit/posix/src/pthreadcreate.c b/cpukit/posix/src/pthreadcreate.c
index f53cd5e310..055d304699 100644
--- a/cpukit/posix/src/pthreadcreate.c
+++ b/cpukit/posix/src/pthreadcreate.c
@@ -74,7 +74,6 @@ int pthread_create(
   bool                                valid;
   Thread_Configuration                config;
   Status_Control                      status;
-  bool                                ok;
   Thread_Control                     *the_thread;
   Thread_Control                     *executing;
   int                                 schedpolicy = SCHED_RR;
@@ -289,7 +288,7 @@ int pthread_create(
    *  POSIX threads are allocated and started in one operation.
    */
   _ISR_lock_ISR_disable( &lock_context );
-  ok = _Thread_Start( the_thread, &entry, &lock_context );
+  status = _Thread_Start( the_thread, &entry, &lock_context );
 
   #if defined(RTEMS_DEBUG)
     /*
@@ -298,7 +297,7 @@ int pthread_create(
      *  NOTE: This can only happen if someone slips in and touches the
      *        thread while we are creating it.
      */
-    if ( !ok ) {
+    if ( status != STATUS_SUCCESSFUL ) {
       _Thread_Free( &_POSIX_Threads_Information, the_thread );
       _Objects_Allocator_unlock();
       return EINVAL;
diff --git a/cpukit/rtems/src/taskstart.c b/cpukit/rtems/src/taskstart.c
index da29240961..eca9b5795d 100644
--- a/cpukit/rtems/src/taskstart.c
+++ b/cpukit/rtems/src/taskstart.c
@@ -21,6 +21,7 @@
 #endif
 
 #include <rtems/rtems/tasks.h>
+#include <rtems/rtems/statusimpl.h>
 #include <rtems/score/threadimpl.h>
 
 rtems_status_code rtems_task_start(
@@ -40,7 +41,7 @@ rtems_status_code rtems_task_start(
   };
   Thread_Control   *the_thread;
   ISR_lock_Context  lock_context;
-  bool              ok;
+  Status_Control    status;
 
   the_thread = _Thread_Get( id, &lock_context );
 
@@ -54,7 +55,7 @@ rtems_status_code rtems_task_start(
     return RTEMS_INVALID_ID;
   }
 
-  ok = _Thread_Start( the_thread, &entry, &lock_context );
+  status = _Thread_Start( the_thread, &entry, &lock_context );
 
-  return ok ? RTEMS_SUCCESSFUL : RTEMS_INCORRECT_STATE;
+  return _Status_Get( status );
 }
diff --git a/cpukit/score/src/threadstart.c b/cpukit/score/src/threadstart.c
index e75c536a2c..8c1732a35a 100644
--- a/cpukit/score/src/threadstart.c
+++ b/cpukit/score/src/threadstart.c
@@ -24,7 +24,7 @@
 #include <rtems/score/isrlevel.h>
 #include <rtems/score/userextimpl.h>
 
-bool _Thread_Start(
+Status_Control _Thread_Start(
   Thread_Control                 *the_thread,
   const Thread_Entry_information *entry,
   ISR_lock_Context               *lock_context
@@ -36,7 +36,7 @@ bool _Thread_Start(
 
   if ( !_States_Is_dormant( the_thread->current_state ) ) {
     _Thread_State_release( the_thread, lock_context );
-    return false;
+    return STATUS_INCORRECT_STATE;
   }
 
   the_thread->Start.Entry = *entry;
@@ -49,5 +49,5 @@ bool _Thread_Start(
   _User_extensions_Thread_start( the_thread );
 
   _Thread_Dispatch_enable( cpu_self );
-  return true;
+  return STATUS_SUCCESSFUL;
 }
-- 
2.26.2



More information about the devel mailing list