[PATCH 2/2] score: Simplify _Thread_Start()

Sebastian Huber sebastian.huber at embedded-brains.de
Fri Jan 8 14:37:05 UTC 2016


---
 cpukit/posix/src/pthreadcreate.c              |  2 +-
 cpukit/rtems/src/taskstart.c                  |  2 +-
 cpukit/score/include/rtems/score/threadimpl.h |  6 +-----
 cpukit/score/src/threadcreateidle.c           | 31 +++++++++++++++++----------
 cpukit/score/src/threadstart.c                | 17 ++-------------
 5 files changed, 25 insertions(+), 33 deletions(-)

diff --git a/cpukit/posix/src/pthreadcreate.c b/cpukit/posix/src/pthreadcreate.c
index 611477e..3185ab6 100644
--- a/cpukit/posix/src/pthreadcreate.c
+++ b/cpukit/posix/src/pthreadcreate.c
@@ -228,7 +228,7 @@ int pthread_create(
   /*
    *  POSIX threads are allocated and started in one operation.
    */
-  status = _Thread_Start( the_thread, &entry, NULL );
+  status = _Thread_Start( the_thread, &entry );
 
   #if defined(RTEMS_DEBUG)
     /*
diff --git a/cpukit/rtems/src/taskstart.c b/cpukit/rtems/src/taskstart.c
index 39b3e9c..416c2df 100644
--- a/cpukit/rtems/src/taskstart.c
+++ b/cpukit/rtems/src/taskstart.c
@@ -64,7 +64,7 @@ rtems_status_code rtems_task_start(
   switch ( location ) {
 
     case OBJECTS_LOCAL:
-      successfully_started = _Thread_Start( the_thread, &entry, NULL );
+      successfully_started = _Thread_Start( the_thread, &entry );
 
       _Objects_Put( &the_thread->Object );
 
diff --git a/cpukit/score/include/rtems/score/threadimpl.h b/cpukit/score/include/rtems/score/threadimpl.h
index f212e23..4177a97 100644
--- a/cpukit/score/include/rtems/score/threadimpl.h
+++ b/cpukit/score/include/rtems/score/threadimpl.h
@@ -187,14 +187,10 @@ bool _Thread_Initialize(
  *
  *  @param the_thread The thread to be started.
  *  @param entry The thread entry information.
- *  @param[in,out] cpu The processor if used to start an idle thread
- *  during system initialization.  Must be set to @c NULL to start a normal
- *  thread.
  */
 bool _Thread_Start(
   Thread_Control                 *the_thread,
-  const Thread_Entry_information *entry,
-  Per_CPU_Control                *cpu
+  const Thread_Entry_information *entry
 );
 
 bool _Thread_Restart(
diff --git a/cpukit/score/src/threadcreateidle.c b/cpukit/score/src/threadcreateidle.c
index e9d12dc..3430881 100644
--- a/cpukit/score/src/threadcreateidle.c
+++ b/cpukit/score/src/threadcreateidle.c
@@ -21,20 +21,14 @@
 #include <rtems/score/threadimpl.h>
 #include <rtems/score/schedulerimpl.h>
 #include <rtems/score/stackimpl.h>
+#include <rtems/score/userextimpl.h>
 #include <rtems/config.h>
 
 static void _Thread_Create_idle_for_cpu( Per_CPU_Control *cpu )
 {
-  Thread_Entry_information entry = {
-    .adaptor = _Thread_Entry_adaptor_idle,
-    .Kinds = {
-      .Idle = {
-        .entry = rtems_configuration_get_idle_task()
-      }
-    }
-  };
-  Objects_Name    name;
-  Thread_Control *idle;
+  Objects_Name             name;
+  Thread_Control          *idle;
+  const Scheduler_Control *scheduler;
 
   name.name_u32 = _Objects_Build_name( 'I', 'D', 'L', 'E' );
 
@@ -67,7 +61,22 @@ static void _Thread_Create_idle_for_cpu( Per_CPU_Control *cpu )
   cpu->heir      =
   cpu->executing = idle;
 
-  _Thread_Start( idle, &entry, cpu );
+  idle->Start.Entry.adaptor = _Thread_Entry_adaptor_idle;
+  idle->Start.Entry.Kinds.Idle.entry = rtems_configuration_get_idle_task();
+
+  _Thread_Load_environment( idle );
+
+  scheduler = _Scheduler_Get_by_CPU( cpu );
+
+#if defined(RTEMS_SMP)
+  if (scheduler == NULL) {
+    return;
+  }
+#endif
+
+  idle->current_state = STATES_READY;
+  _Scheduler_Start_idle( scheduler, idle, cpu );
+  _User_extensions_Thread_start( idle );
 }
 
 void _Thread_Create_idle( void )
diff --git a/cpukit/score/src/threadstart.c b/cpukit/score/src/threadstart.c
index 97399ba..0cdf2bc 100644
--- a/cpukit/score/src/threadstart.c
+++ b/cpukit/score/src/threadstart.c
@@ -21,30 +21,17 @@
 
 #include <rtems/score/threadimpl.h>
 #include <rtems/score/isrlevel.h>
-#include <rtems/score/schedulerimpl.h>
 #include <rtems/score/userextimpl.h>
 
 bool _Thread_Start(
   Thread_Control                 *the_thread,
-  const Thread_Entry_information *entry,
-  Per_CPU_Control                *cpu
+  const Thread_Entry_information *entry
 )
 {
   if ( _States_Is_dormant( the_thread->current_state ) ) {
     the_thread->Start.Entry = *entry;
     _Thread_Load_environment( the_thread );
-
-    if ( cpu == NULL ) {
-      _Thread_Ready( the_thread );
-    } else {
-      const Scheduler_Control *scheduler = _Scheduler_Get_by_CPU( cpu );
-
-      if ( scheduler != NULL ) {
-        the_thread->current_state = STATES_READY;
-        _Scheduler_Start_idle( scheduler, the_thread, cpu );
-      }
-    }
-
+    _Thread_Ready( the_thread );
     _User_extensions_Thread_start( the_thread );
 
     return true;
-- 
1.8.4.5




More information about the devel mailing list