source: rtems/cpukit/sapi/src/exinit.c @ 51f823c9

4.115
Last change on this file since 51f823c9 was 51f823c9, checked in by Sebastian Huber <sebastian.huber@…>, on 03/18/14 at 07:28:14

posix: Use interal mutex for once implementation

Enable pthread_once() for all configurations. The pthread_once()
function is one means to initialize POSIX keys. Another use case is the
C++ support.

  • Property mode set to 100644
File size: 5.7 KB
Line 
1/**
2 * @file
3 *
4 * @brief Initialization Manager
5 *
6 * @ingroup ClassicRTEMS
7 */
8
9/*
10 *  COPYRIGHT (c) 1989-2014.
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.com/license/LICENSE.
16 */
17
18#if HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22/*
23 *  SCORE_INIT and SAPI_INIT are defined so all of the super core and
24 *  super API data will be included in this object file.
25 */
26
27#define SAPI_INIT
28#define SCORE_INIT
29
30#include <rtems/system.h>
31#include <rtems/config.h>
32#include <rtems/debug.h>
33#include <rtems/extensionimpl.h>
34#include <rtems/init.h>
35#include <rtems/io.h>
36#include <rtems/score/sysstate.h>
37
38#include <rtems/score/apiext.h>
39#include <rtems/score/apimutex.h>
40#include <rtems/score/copyrt.h>
41#include <rtems/score/cpusetimpl.h>
42#include <rtems/score/heap.h>
43#include <rtems/score/interr.h>
44#include <rtems/score/isr.h>
45#include <rtems/score/priority.h>
46#include <rtems/score/schedulerimpl.h>
47#include <rtems/score/smpimpl.h>
48#include <rtems/score/threadimpl.h>
49#include <rtems/score/todimpl.h>
50#include <rtems/score/userextimpl.h>
51#include <rtems/score/watchdogimpl.h>
52#include <rtems/score/wkspace.h>
53
54#include <rtems/sptables.h>
55
56
57#include <rtems/rtems/rtemsapi.h>
58#include <rtems/posix/posixapi.h>
59
60Objects_Information *_Internal_Objects[ OBJECTS_INTERNAL_CLASSES_LAST + 1 ];
61
62void rtems_initialize_data_structures(void)
63{
64  /*
65   *  Dispatching and interrupts are disabled until the end of the
66   *  initialization sequence.  This prevents an inadvertent context
67   *  switch before the executive is initialized.
68   *
69   *  WARNING: Interrupts should have been disabled by the BSP and
70   *           are disabled by boot_card().
71   */
72
73  #if defined(RTEMS_MULTIPROCESSING)
74    /*
75     *  Initialize the system state based on whether this is an MP system.
76     *  In an MP configuration, internally we view single processor
77     *  systems as a very restricted multiprocessor system.
78     */
79    _Configuration_MP_table = rtems_configuration_get_user_multiprocessing_table();
80
81    if ( _Configuration_MP_table == NULL ) {
82      _Configuration_MP_table =
83        (void *)&_Initialization_Default_multiprocessing_table;
84      _System_state_Handler_initialization( FALSE );
85    } else {
86      _System_state_Handler_initialization( TRUE );
87    }
88  #else
89    _System_state_Handler_initialization( FALSE );
90  #endif
91
92  /*
93   * Initialize any target architecture specific support as early as possible
94   */
95  _CPU_Initialize();
96
97  #if defined(RTEMS_MULTIPROCESSING)
98    _Objects_MP_Handler_early_initialization();
99  #endif
100
101  /*
102   *  Do this as early as possible to ensure no debugging output
103   *  is even attempted to be printed.
104   */
105  _Debug_Manager_initialization();
106
107  _API_extensions_Initialization();
108
109  _Thread_Dispatch_initialization();
110
111  _User_extensions_Handler_initialization();
112  _ISR_Handler_initialization();
113
114  /*
115   * Initialize the internal support API and allocator Mutex
116   */
117  _Objects_Information_table[OBJECTS_INTERNAL_API] = _Internal_Objects;
118
119  _API_Mutex_Initialization( 2 );
120  _API_Mutex_Allocate( &_RTEMS_Allocator_Mutex );
121  _API_Mutex_Allocate( &_Once_Mutex );
122
123  _Watchdog_Handler_initialization();
124  _TOD_Handler_initialization();
125
126  _Thread_Handler_initialization();
127
128  _Scheduler_Handler_initialization();
129
130  #if defined(RTEMS_MULTIPROCESSING)
131    _Objects_MP_Handler_initialization();
132    _MPCI_Handler_initialization( RTEMS_TIMEOUT );
133  #endif
134
135  _SMP_Handler_initialize();
136
137  _CPU_set_Handler_initialization();
138
139/* MANAGERS */
140
141  _RTEMS_API_Initialize();
142
143  _Extension_Manager_initialization();
144
145  _IO_Manager_initialization();
146
147  _POSIX_API_Initialize();
148
149  _System_state_Set( SYSTEM_STATE_BEFORE_MULTITASKING );
150
151  /*
152   *  No threads should be created before this point!!!
153   *  _Thread_Executing and _Thread_Heir are not set.
154   *
155   *  At this point all API extensions are in place.  After the call to
156   *  _Thread_Create_idle() _Thread_Executing and _Thread_Heir will be set.
157   */
158  _Thread_Create_idle();
159
160  /*
161   *  Scheduling can properly occur now as long as we avoid dispatching.
162   */
163}
164
165void rtems_initialize_before_drivers(void)
166{
167
168  #if defined(RTEMS_MULTIPROCESSING)
169    _MPCI_Create_server();
170  #endif
171
172  #if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
173    /*
174     *  Run the API and BSPs predriver hook.
175     */
176    _API_extensions_Run_predriver();
177  #endif
178}
179
180void rtems_initialize_device_drivers(void)
181{
182  /*
183   *  Initialize all the device drivers and initialize the MPCI layer.
184   *
185   *  NOTE:  The MPCI may be build upon a device driver.
186   */
187
188  _IO_Initialize_all_drivers();
189
190  #if defined(RTEMS_MULTIPROCESSING)
191    if ( _System_state_Is_multiprocessing ) {
192      _MPCI_Initialization();
193      _MPCI_Internal_packets_Send_process_packet(
194        MPCI_PACKETS_SYSTEM_VERIFY
195      );
196    }
197  #endif
198
199  /*
200   *  Run the APIs and BSPs postdriver hooks.
201   *
202   *  The API extensions are supposed to create user initialization tasks.
203   */
204  _API_extensions_Run_postdriver();
205}
206
207void rtems_initialize_start_multitasking(void)
208{
209  _System_state_Set( SYSTEM_STATE_UP );
210
211  _SMP_Request_start_multitasking();
212
213  _Thread_Start_multitasking();
214
215  /*******************************************************************
216   *******************************************************************
217   *******************************************************************
218   ******                 APPLICATION RUNS HERE                 ******
219   ******              THE FUNCTION NEVER RETURNS               ******
220   *******************************************************************
221   *******************************************************************
222   *******************************************************************/
223}
Note: See TracBrowser for help on using the repository browser.