1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Initialize Thread Handler |
---|
5 | * @ingroup ScoreThread |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2011. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.org/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <rtems/score/threadimpl.h> |
---|
22 | #include <rtems/score/interr.h> |
---|
23 | #include <rtems/score/scheduler.h> |
---|
24 | #include <rtems/score/wkspace.h> |
---|
25 | |
---|
26 | #define THREAD_OFFSET_ASSERT( field ) \ |
---|
27 | RTEMS_STATIC_ASSERT( \ |
---|
28 | offsetof( Thread_Control, field ) == offsetof( Thread_Proxy_control, field ), \ |
---|
29 | field \ |
---|
30 | ) |
---|
31 | |
---|
32 | THREAD_OFFSET_ASSERT( Object ); |
---|
33 | THREAD_OFFSET_ASSERT( current_state ); |
---|
34 | THREAD_OFFSET_ASSERT( current_priority ); |
---|
35 | THREAD_OFFSET_ASSERT( real_priority ); |
---|
36 | THREAD_OFFSET_ASSERT( priority_generation ); |
---|
37 | THREAD_OFFSET_ASSERT( priority_restore_hint ); |
---|
38 | THREAD_OFFSET_ASSERT( resource_count ); |
---|
39 | THREAD_OFFSET_ASSERT( Wait ); |
---|
40 | THREAD_OFFSET_ASSERT( Timer ); |
---|
41 | #if defined(RTEMS_MULTIPROCESSING) |
---|
42 | THREAD_OFFSET_ASSERT( receive_packet ); |
---|
43 | #endif |
---|
44 | |
---|
45 | void _Thread_Initialize_information( |
---|
46 | Thread_Information *information, |
---|
47 | Objects_APIs the_api, |
---|
48 | uint16_t the_class, |
---|
49 | uint32_t maximum, |
---|
50 | bool is_string, |
---|
51 | uint32_t maximum_name_length |
---|
52 | #if defined(RTEMS_MULTIPROCESSING) |
---|
53 | , |
---|
54 | bool supports_global |
---|
55 | #endif |
---|
56 | ) |
---|
57 | { |
---|
58 | _Objects_Initialize_information( |
---|
59 | &information->Objects, |
---|
60 | the_api, |
---|
61 | the_class, |
---|
62 | maximum, |
---|
63 | _Thread_Control_size, |
---|
64 | is_string, |
---|
65 | maximum_name_length |
---|
66 | #if defined(RTEMS_MULTIPROCESSING) |
---|
67 | , |
---|
68 | supports_global, |
---|
69 | NULL |
---|
70 | #endif |
---|
71 | ); |
---|
72 | |
---|
73 | _Freechain_Initialize( |
---|
74 | &information->Free_thread_queue_heads, |
---|
75 | _Workspace_Allocate_or_fatal_error, |
---|
76 | _Objects_Maximum_per_allocation( maximum ), |
---|
77 | THREAD_QUEUE_HEADS_SIZE( _Scheduler_Count ) |
---|
78 | ); |
---|
79 | } |
---|
80 | |
---|
81 | void _Thread_Handler_initialization(void) |
---|
82 | { |
---|
83 | rtems_stack_allocate_init_hook stack_allocate_init_hook = |
---|
84 | rtems_configuration_get_stack_allocate_init_hook(); |
---|
85 | #if defined(RTEMS_MULTIPROCESSING) |
---|
86 | uint32_t maximum_proxies = |
---|
87 | _Configuration_MP_table->maximum_proxies; |
---|
88 | #endif |
---|
89 | |
---|
90 | if ( rtems_configuration_get_stack_allocate_hook() == NULL || |
---|
91 | rtems_configuration_get_stack_free_hook() == NULL) |
---|
92 | _Terminate( |
---|
93 | INTERNAL_ERROR_CORE, |
---|
94 | true, |
---|
95 | INTERNAL_ERROR_BAD_STACK_HOOK |
---|
96 | ); |
---|
97 | |
---|
98 | if ( stack_allocate_init_hook != NULL ) |
---|
99 | (*stack_allocate_init_hook)( rtems_configuration_get_stack_space_size() ); |
---|
100 | |
---|
101 | #if defined(RTEMS_MULTIPROCESSING) |
---|
102 | _Thread_MP_Handler_initialization( maximum_proxies ); |
---|
103 | #endif |
---|
104 | |
---|
105 | /* |
---|
106 | * Initialize the internal class of threads. We need an IDLE thread |
---|
107 | * per CPU in an SMP system. In addition, if this is a loosely |
---|
108 | * coupled multiprocessing system, account for the MPCI Server Thread. |
---|
109 | */ |
---|
110 | _Thread_Initialize_information( |
---|
111 | &_Thread_Internal_information, |
---|
112 | OBJECTS_INTERNAL_API, |
---|
113 | OBJECTS_INTERNAL_THREADS, |
---|
114 | _Thread_Get_maximum_internal_threads(), |
---|
115 | false, /* true if names for this object are strings */ |
---|
116 | 8 /* maximum length of each object's name */ |
---|
117 | #if defined(RTEMS_MULTIPROCESSING) |
---|
118 | , |
---|
119 | false /* true if this is a global object class */ |
---|
120 | #endif |
---|
121 | ); |
---|
122 | |
---|
123 | } |
---|