source: rtems/cpukit/score/src/threadglobalconstruction.c @ a38ced2

4.115
Last change on this file since a38ced2 was a38ced2, checked in by Sebastian Huber <sebastian.huber@…>, on 10/10/14 at 07:09:19

score: Rework global construction

Ensure that the global construction is performed in the context of the
first initialization thread. On SMP this was not guaranteed in the
previous implementation.

  • Property mode set to 100644
File size: 2.1 KB
Line 
1/**
2 * @file
3 *
4 * @brief Thread Global Construction
5 *
6 * @ingroup ScoreThread
7 */
8
9/*
10 *  COPYRIGHT (c) 1989-2012.
11 *  On-Line Applications Research Corporation (OAR).
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.rtems.org/license/LICENSE.
16 */
17
18#if HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22#include <rtems/score/threadimpl.h>
23#include <rtems/score/assert.h>
24#include <rtems/rtems/config.h>
25#include <rtems/posix/config.h>
26
27/*
28 *  Conditional magic to determine what style of C++ constructor
29 *  initialization this target and compiler version uses.
30 */
31#if defined(__USE_INIT_FINI__)
32  #if defined(__M32R__)
33    #define INIT_NAME __init
34  #elif defined(__ARM_EABI__)
35    #define INIT_NAME __libc_init_array
36  #else
37    #define INIT_NAME _init
38  #endif
39
40  extern void INIT_NAME(void);
41  #define EXECUTE_GLOBAL_CONSTRUCTORS
42#endif
43
44#if defined(__USE__MAIN__)
45  extern void __main(void);
46  #define INIT_NAME __main
47  #define EXECUTE_GLOBAL_CONSTRUCTORS
48#endif
49
50void *_Thread_Global_construction( void )
51{
52  Thread_Control *executing;
53  Thread_Entry    entry_point;
54
55#if defined(EXECUTE_GLOBAL_CONSTRUCTORS)
56  /*
57   *  _init could be a weak symbol and we SHOULD test it but it isn't
58   *  in any configuration I know of and it generates a warning on every
59   *  RTEMS target configuration.  --joel (12 May 2007)
60   */
61  INIT_NAME();
62#endif
63
64#if defined(RTEMS_POSIX_API)
65  if ( Configuration_RTEMS_API.number_of_initialization_tasks > 0 ) {
66#endif
67    entry_point = (Thread_Entry)
68      Configuration_RTEMS_API.User_initialization_tasks_table[ 0 ].entry_point;
69#if defined(RTEMS_POSIX_API)
70  } else {
71    entry_point = (Thread_Entry)
72      Configuration_POSIX_API
73        .User_initialization_threads_table[ 0 ].thread_entry;
74  }
75#endif
76
77  _Thread_Disable_dispatch();
78
79  executing = _Thread_Executing;
80  executing->Start.entry_point = entry_point;
81
82  _Thread_Restart(
83    executing,
84    executing,
85    executing->Start.pointer_argument,
86    executing->Start.numeric_argument
87  );
88
89  _Thread_Enable_dispatch();
90
91  _Assert_Not_reached();
92
93  return NULL;
94}
Note: See TracBrowser for help on using the repository browser.