summaryrefslogtreecommitdiffstats
path: root/cpukit/score/src
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2017-11-17 06:36:54 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2017-11-22 09:40:22 +0100
commita7dcef97e93240b1947a0094b1af91e9b9324a30 (patch)
tree41a02234f131870bcb0c7bcc025682bce45fa582 /cpukit/score/src
parentbsps: Add default getentropy() implementation (diff)
downloadrtems-a7dcef97e93240b1947a0094b1af91e9b9324a30.tar.bz2
score: Simplify global construction
Update #3243.
Diffstat (limited to 'cpukit/score/src')
-rw-r--r--cpukit/score/src/threadglobalconstruction.c63
-rw-r--r--cpukit/score/src/threadhandler.c46
2 files changed, 46 insertions, 63 deletions
diff --git a/cpukit/score/src/threadglobalconstruction.c b/cpukit/score/src/threadglobalconstruction.c
deleted file mode 100644
index 7ce1862d8c..0000000000
--- a/cpukit/score/src/threadglobalconstruction.c
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- * @file
- *
- * @brief Thread Global Construction
- *
- * @ingroup ScoreThread
- */
-
-/*
- * COPYRIGHT (c) 1989-2012.
- * On-Line Applications Research Corporation (OAR).
- *
- * 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>
-
-/*
- * Conditional magic to determine what style of C++ constructor
- * initialization this target and compiler version uses.
- */
-#if defined(__USE_INIT_FINI__)
- #if defined(__ARM_EABI__)
- #define INIT_NAME __libc_init_array
- #else
- #define INIT_NAME _init
- #endif
-
- extern void INIT_NAME(void);
- #define EXECUTE_GLOBAL_CONSTRUCTORS
-#endif
-
-#if defined(__USE__MAIN__)
- extern void __main(void);
- #define INIT_NAME __main
- #define EXECUTE_GLOBAL_CONSTRUCTORS
-#endif
-
-void _Thread_Global_construction(
- Thread_Control *executing,
- const Thread_Entry_information *entry
-)
-{
- ISR_lock_Context lock_context;
-
-#if defined(EXECUTE_GLOBAL_CONSTRUCTORS)
- /*
- * _init could be a weak symbol and we SHOULD test it but it isn't
- * in any configuration I know of and it generates a warning on every
- * RTEMS target configuration. --joel (12 May 2007)
- */
- INIT_NAME();
-#endif
-
- _ISR_lock_ISR_disable( &lock_context );
- _Thread_Restart_self( _Thread_Executing, entry, &lock_context );
-}
diff --git a/cpukit/score/src/threadhandler.c b/cpukit/score/src/threadhandler.c
index 7267577baf..9201c55607 100644
--- a/cpukit/score/src/threadhandler.c
+++ b/cpukit/score/src/threadhandler.c
@@ -24,6 +24,50 @@
#include <rtems/score/isrlevel.h>
#include <rtems/score/userextimpl.h>
+/*
+ * Conditional magic to determine what style of C++ constructor
+ * initialization this target and compiler version uses.
+ */
+#if defined(__USE_INIT_FINI__)
+ #if defined(__ARM_EABI__)
+ #define INIT_NAME __libc_init_array
+ #else
+ #define INIT_NAME _init
+ #endif
+
+ extern void INIT_NAME(void);
+ #define EXECUTE_GLOBAL_CONSTRUCTORS
+#endif
+
+#if defined(__USE__MAIN__)
+ extern void __main(void);
+ #define INIT_NAME __main
+ #define EXECUTE_GLOBAL_CONSTRUCTORS
+#endif
+
+Objects_Id _Thread_Global_constructor;
+
+static void _Thread_Global_construction( Thread_Control *executing )
+{
+#if defined(EXECUTE_GLOBAL_CONSTRUCTORS)
+ if ( executing->Object.id == _Thread_Global_constructor ) {
+ /*
+ * Prevent double construction in case the initialization thread is deleted
+ * and then recycled. There is not need for extra synchronization since
+ * this variable is set during the sequential system boot procedure.
+ */
+ _Thread_Global_constructor = 0;
+
+ /*
+ * _init could be a weak symbol and we SHOULD test it but it isn't
+ * in any configuration I know of and it generates a warning on every
+ * RTEMS target configuration. --joel (12 May 2007)
+ */
+ INIT_NAME();
+ }
+#endif
+}
+
void _Thread_Handler( void )
{
Thread_Control *executing;
@@ -80,6 +124,8 @@ void _Thread_Handler( void )
*/
_User_extensions_Thread_begin( executing );
+ _Thread_Global_construction( executing );
+
/*
* RTEMS supports multiple APIs and each API can define a different
* thread/task prototype. The following code supports invoking the