summaryrefslogtreecommitdiffstats
path: root/cpukit/score/src
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2016-01-07 09:55:45 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2016-01-11 08:47:01 +0100
commitccd54344d904b657123e4e4ba795a32212382be2 (patch)
treed490d77b6173f586137036ed07ec5bd27d8ca65a /cpukit/score/src
parentsmptests/README: Delete obsolete information (diff)
downloadrtems-ccd54344d904b657123e4e4ba795a32212382be2.tar.bz2
score: Introduce Thread_Entry_information
This avoids potential dead code in _Thread_Handler(). It gets rid of the dangerous function pointer casts. Update #2514.
Diffstat (limited to 'cpukit/score/src')
-rw-r--r--cpukit/score/src/threadcreateidle.c17
-rw-r--r--cpukit/score/src/threadentryadaptoridle.c26
-rw-r--r--cpukit/score/src/threadentryadaptornumeric.c26
-rw-r--r--cpukit/score/src/threadentryadaptorpointer.c26
-rw-r--r--cpukit/score/src/threadglobalconstruction.c19
-rw-r--r--cpukit/score/src/threadhandler.c37
-rw-r--r--cpukit/score/src/threadrestart.c10
-rw-r--r--cpukit/score/src/threadstart.c17
8 files changed, 104 insertions, 74 deletions
diff --git a/cpukit/score/src/threadcreateidle.c b/cpukit/score/src/threadcreateidle.c
index 8a5812f1a5..e9d12dc963 100644
--- a/cpukit/score/src/threadcreateidle.c
+++ b/cpukit/score/src/threadcreateidle.c
@@ -25,6 +25,14 @@
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;
@@ -59,14 +67,7 @@ static void _Thread_Create_idle_for_cpu( Per_CPU_Control *cpu )
cpu->heir =
cpu->executing = idle;
- _Thread_Start(
- idle,
- THREAD_START_NUMERIC,
- rtems_configuration_get_idle_task(),
- NULL,
- 0,
- cpu
- );
+ _Thread_Start( idle, &entry, cpu );
}
void _Thread_Create_idle( void )
diff --git a/cpukit/score/src/threadentryadaptoridle.c b/cpukit/score/src/threadentryadaptoridle.c
new file mode 100644
index 0000000000..e98f562a30
--- /dev/null
+++ b/cpukit/score/src/threadentryadaptoridle.c
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2015 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Dornierstr. 4
+ * 82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#if HAVE_CONFIG_H
+ #include "config.h"
+#endif
+
+#include <rtems/score/threadimpl.h>
+
+void _Thread_Entry_adaptor_idle( Thread_Control *executing )
+{
+ const Thread_Entry_idle *idle = &executing->Start.Entry.Kinds.Idle;
+
+ ( *idle->entry )( 0 );
+}
diff --git a/cpukit/score/src/threadentryadaptornumeric.c b/cpukit/score/src/threadentryadaptornumeric.c
new file mode 100644
index 0000000000..acc06f0614
--- /dev/null
+++ b/cpukit/score/src/threadentryadaptornumeric.c
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2015 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Dornierstr. 4
+ * 82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#if HAVE_CONFIG_H
+ #include "config.h"
+#endif
+
+#include <rtems/score/threadimpl.h>
+
+void _Thread_Entry_adaptor_numeric( Thread_Control *executing )
+{
+ const Thread_Entry_numeric *numeric = &executing->Start.Entry.Kinds.Numeric;
+
+ ( *numeric->entry )( numeric->argument );
+}
diff --git a/cpukit/score/src/threadentryadaptorpointer.c b/cpukit/score/src/threadentryadaptorpointer.c
new file mode 100644
index 0000000000..65866d886f
--- /dev/null
+++ b/cpukit/score/src/threadentryadaptorpointer.c
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2015 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Dornierstr. 4
+ * 82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#if HAVE_CONFIG_H
+ #include "config.h"
+#endif
+
+#include <rtems/score/threadimpl.h>
+
+void _Thread_Entry_adaptor_pointer( Thread_Control *executing )
+{
+ const Thread_Entry_pointer *pointer = &executing->Start.Entry.Kinds.Pointer;
+
+ executing->Wait.return_argument = ( *pointer->entry )( pointer->argument );
+}
diff --git a/cpukit/score/src/threadglobalconstruction.c b/cpukit/score/src/threadglobalconstruction.c
index 56a6df11a9..1e84124c55 100644
--- a/cpukit/score/src/threadglobalconstruction.c
+++ b/cpukit/score/src/threadglobalconstruction.c
@@ -44,10 +44,11 @@
#define EXECUTE_GLOBAL_CONSTRUCTORS
#endif
-void _Thread_Global_construction( Thread_Entry entry_point )
+void _Thread_Global_construction(
+ Thread_Control *executing,
+ const Thread_Entry_information *entry
+)
{
- Thread_Control *executing;
-
#if defined(EXECUTE_GLOBAL_CONSTRUCTORS)
/*
* _init could be a weak symbol and we SHOULD test it but it isn't
@@ -58,17 +59,7 @@ void _Thread_Global_construction( Thread_Entry entry_point )
#endif
_Thread_Disable_dispatch();
-
- executing = _Thread_Executing;
- executing->Start.entry_point = entry_point;
-
- _Thread_Restart(
- executing,
- executing,
- executing->Start.pointer_argument,
- executing->Start.numeric_argument
- );
-
+ _Thread_Restart( executing, executing, entry );
_Thread_Enable_dispatch();
_Assert_Not_reached();
diff --git a/cpukit/score/src/threadhandler.c b/cpukit/score/src/threadhandler.c
index fd828a2325..2429de57bc 100644
--- a/cpukit/score/src/threadhandler.c
+++ b/cpukit/score/src/threadhandler.c
@@ -90,41 +90,12 @@ void _Thread_Handler( void )
* thread/task prototype. The following code supports invoking the
* user thread entry point using the prototype expected.
*/
- if ( executing->Start.prototype == THREAD_START_NUMERIC ) {
- executing->Wait.return_argument =
- (*(Thread_Entry_numeric) executing->Start.entry_point)(
- executing->Start.numeric_argument
- );
- }
- #if defined(RTEMS_POSIX_API)
- else if ( executing->Start.prototype == THREAD_START_POINTER ) {
- executing->Wait.return_argument =
- (*(Thread_Entry_pointer) executing->Start.entry_point)(
- executing->Start.pointer_argument
- );
- }
- #endif
- #if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
- else if ( executing->Start.prototype == THREAD_START_BOTH_POINTER_FIRST ) {
- executing->Wait.return_argument =
- (*(Thread_Entry_both_pointer_first) executing->Start.entry_point)(
- executing->Start.pointer_argument,
- executing->Start.numeric_argument
- );
- }
- else if ( executing->Start.prototype == THREAD_START_BOTH_NUMERIC_FIRST ) {
- executing->Wait.return_argument =
- (*(Thread_Entry_both_numeric_first) executing->Start.entry_point)(
- executing->Start.numeric_argument,
- executing->Start.pointer_argument
- );
- }
- #endif
+ ( *executing->Start.Entry.adaptor )( executing );
/*
- * In the switch above, the return code from the user thread body
- * was placed in return_argument. This assumed that if it returned
- * anything (which is not supporting in all APIs), then it would be
+ * In the call above, the return code from the user thread body which return
+ * something was placed in return_argument. This assumed that if it
+ * returned anything (which is not supporting in all APIs), then it would be
* able to fit in a (void *).
*/
diff --git a/cpukit/score/src/threadrestart.c b/cpukit/score/src/threadrestart.c
index 2b1fef94fc..03b1fba8ff 100644
--- a/cpukit/score/src/threadrestart.c
+++ b/cpukit/score/src/threadrestart.c
@@ -356,15 +356,13 @@ void _Thread_Close( Thread_Control *the_thread, Thread_Control *executing )
}
bool _Thread_Restart(
- Thread_Control *the_thread,
- Thread_Control *executing,
- void *pointer_argument,
- Thread_Entry_numeric_type numeric_argument
+ Thread_Control *the_thread,
+ Thread_Control *executing,
+ const Thread_Entry_information *entry
)
{
if ( !_States_Is_dormant( the_thread->current_state ) ) {
- the_thread->Start.pointer_argument = pointer_argument;
- the_thread->Start.numeric_argument = numeric_argument;
+ the_thread->Start.Entry = *entry;
_Thread_Request_life_change(
the_thread,
diff --git a/cpukit/score/src/threadstart.c b/cpukit/score/src/threadstart.c
index dda9495a35..97399ba524 100644
--- a/cpukit/score/src/threadstart.c
+++ b/cpukit/score/src/threadstart.c
@@ -25,22 +25,13 @@
#include <rtems/score/userextimpl.h>
bool _Thread_Start(
- Thread_Control *the_thread,
- Thread_Start_types the_prototype,
- void *entry_point,
- void *pointer_argument,
- Thread_Entry_numeric_type numeric_argument,
- Per_CPU_Control *cpu
+ Thread_Control *the_thread,
+ const Thread_Entry_information *entry,
+ Per_CPU_Control *cpu
)
{
if ( _States_Is_dormant( the_thread->current_state ) ) {
-
- the_thread->Start.entry_point = (Thread_Entry) entry_point;
-
- the_thread->Start.prototype = the_prototype;
- the_thread->Start.pointer_argument = pointer_argument;
- the_thread->Start.numeric_argument = numeric_argument;
-
+ the_thread->Start.Entry = *entry;
_Thread_Load_environment( the_thread );
if ( cpu == NULL ) {