1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Objects MP Support |
---|
5 | * @ingroup ScoreObjectMP |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-1999. |
---|
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.com/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <rtems/system.h> |
---|
22 | #include <rtems/config.h> |
---|
23 | #include <rtems/score/interr.h> |
---|
24 | #include <rtems/score/object.h> |
---|
25 | #include <rtems/score/wkspace.h> |
---|
26 | #include <rtems/score/thread.h> |
---|
27 | |
---|
28 | void _Objects_MP_Handler_early_initialization(void) |
---|
29 | { |
---|
30 | uint32_t node; |
---|
31 | uint32_t maximum_nodes; |
---|
32 | |
---|
33 | node = _Configuration_MP_table->node; |
---|
34 | maximum_nodes = _Configuration_MP_table->maximum_nodes; |
---|
35 | |
---|
36 | if ( node < 1 || node > maximum_nodes ) |
---|
37 | _Internal_error_Occurred( |
---|
38 | INTERNAL_ERROR_CORE, |
---|
39 | true, |
---|
40 | INTERNAL_ERROR_INVALID_NODE |
---|
41 | ); |
---|
42 | |
---|
43 | _Objects_Local_node = node; |
---|
44 | _Objects_Maximum_nodes = maximum_nodes; |
---|
45 | } |
---|
46 | |
---|
47 | /* |
---|
48 | * _Objects_MP_Handler_initialization |
---|
49 | * |
---|
50 | */ |
---|
51 | |
---|
52 | void _Objects_MP_Handler_initialization(void) |
---|
53 | { |
---|
54 | |
---|
55 | uint32_t maximum_global_objects; |
---|
56 | |
---|
57 | maximum_global_objects = _Configuration_MP_table->maximum_global_objects; |
---|
58 | |
---|
59 | _Objects_MP_Maximum_global_objects = maximum_global_objects; |
---|
60 | |
---|
61 | if ( maximum_global_objects == 0 ) { |
---|
62 | _Chain_Initialize_empty( &_Objects_MP_Inactive_global_objects ); |
---|
63 | return; |
---|
64 | } |
---|
65 | |
---|
66 | _Chain_Initialize( |
---|
67 | &_Objects_MP_Inactive_global_objects, |
---|
68 | _Workspace_Allocate_or_fatal_error( |
---|
69 | maximum_global_objects * sizeof( Objects_MP_Control ) |
---|
70 | ), |
---|
71 | maximum_global_objects, |
---|
72 | sizeof( Objects_MP_Control ) |
---|
73 | ); |
---|
74 | |
---|
75 | } |
---|
76 | |
---|
77 | void _Objects_MP_Open ( |
---|
78 | Objects_Information *information, |
---|
79 | Objects_MP_Control *the_global_object, |
---|
80 | uint32_t the_name, /* XXX -- wrong for variable */ |
---|
81 | Objects_Id the_id |
---|
82 | ) |
---|
83 | { |
---|
84 | the_global_object->Object.id = the_id; |
---|
85 | the_global_object->name = the_name; |
---|
86 | |
---|
87 | _Chain_Prepend( |
---|
88 | &information->global_table[ _Objects_Get_node( the_id ) ], |
---|
89 | &the_global_object->Object.Node |
---|
90 | ); |
---|
91 | |
---|
92 | } |
---|
93 | |
---|
94 | bool _Objects_MP_Allocate_and_open ( |
---|
95 | Objects_Information *information, |
---|
96 | uint32_t the_name, /* XXX -- wrong for variable */ |
---|
97 | Objects_Id the_id, |
---|
98 | bool is_fatal_error |
---|
99 | ) |
---|
100 | { |
---|
101 | Objects_MP_Control *the_global_object; |
---|
102 | |
---|
103 | the_global_object = _Objects_MP_Allocate_global_object(); |
---|
104 | if ( _Objects_MP_Is_null_global_object( the_global_object ) ) { |
---|
105 | |
---|
106 | if ( is_fatal_error == false ) |
---|
107 | return false; |
---|
108 | |
---|
109 | _Internal_error_Occurred( |
---|
110 | INTERNAL_ERROR_CORE, |
---|
111 | true, |
---|
112 | INTERNAL_ERROR_OUT_OF_GLOBAL_OBJECTS |
---|
113 | ); |
---|
114 | |
---|
115 | } |
---|
116 | |
---|
117 | _Objects_MP_Open( information, the_global_object, the_name, the_id ); |
---|
118 | |
---|
119 | return true; |
---|
120 | } |
---|
121 | |
---|
122 | void _Objects_MP_Close ( |
---|
123 | Objects_Information *information, |
---|
124 | Objects_Id the_id |
---|
125 | ) |
---|
126 | { |
---|
127 | Chain_Control *the_chain; |
---|
128 | Chain_Node *the_node; |
---|
129 | Objects_MP_Control *the_object; |
---|
130 | |
---|
131 | the_chain = &information->global_table[ _Objects_Get_node( the_id ) ]; |
---|
132 | |
---|
133 | for ( the_node = _Chain_First( the_chain ) ; |
---|
134 | !_Chain_Is_tail( the_chain, the_node ) ; |
---|
135 | the_node = _Chain_Next( the_node ) ) { |
---|
136 | |
---|
137 | the_object = (Objects_MP_Control *) the_node; |
---|
138 | |
---|
139 | if ( _Objects_Are_ids_equal( the_object->Object.id, the_id ) ) { |
---|
140 | |
---|
141 | _Chain_Extract( the_node ); |
---|
142 | _Objects_MP_Free_global_object( the_object ); |
---|
143 | return; |
---|
144 | } |
---|
145 | |
---|
146 | } |
---|
147 | |
---|
148 | _Internal_error_Occurred( |
---|
149 | INTERNAL_ERROR_CORE, |
---|
150 | true, |
---|
151 | INTERNAL_ERROR_INVALID_GLOBAL_ID |
---|
152 | ); |
---|
153 | } |
---|
154 | |
---|
155 | Objects_Name_or_id_lookup_errors _Objects_MP_Global_name_search ( |
---|
156 | Objects_Information *information, |
---|
157 | Objects_Name the_name, |
---|
158 | uint32_t nodes_to_search, |
---|
159 | Objects_Id *the_id |
---|
160 | ) |
---|
161 | { |
---|
162 | uint32_t low_node; |
---|
163 | uint32_t high_node; |
---|
164 | uint32_t node_index; |
---|
165 | Chain_Control *the_chain; |
---|
166 | Chain_Node *the_node; |
---|
167 | Objects_MP_Control *the_object; |
---|
168 | uint32_t name_to_use; |
---|
169 | |
---|
170 | name_to_use = the_name.name_u32; /* XXX only fixed length names */ |
---|
171 | |
---|
172 | if ( nodes_to_search > _Objects_Maximum_nodes ) |
---|
173 | return OBJECTS_INVALID_NODE; |
---|
174 | |
---|
175 | if ( information->global_table == NULL ) |
---|
176 | return OBJECTS_INVALID_NAME; |
---|
177 | |
---|
178 | if ( nodes_to_search == OBJECTS_SEARCH_ALL_NODES || |
---|
179 | nodes_to_search == OBJECTS_SEARCH_OTHER_NODES ) { |
---|
180 | low_node = 1; |
---|
181 | high_node = _Objects_Maximum_nodes; |
---|
182 | } else { |
---|
183 | low_node = |
---|
184 | high_node = nodes_to_search; |
---|
185 | } |
---|
186 | |
---|
187 | _Thread_Disable_dispatch(); |
---|
188 | |
---|
189 | for ( node_index = low_node ; node_index <= high_node ; node_index++ ) { |
---|
190 | |
---|
191 | /* |
---|
192 | * NOTE: The local node was search (if necessary) by |
---|
193 | * _Objects_Name_to_id_XXX before this was invoked. |
---|
194 | */ |
---|
195 | |
---|
196 | if ( !_Objects_Is_local_node( node_index ) ) { |
---|
197 | the_chain = &information->global_table[ node_index ]; |
---|
198 | |
---|
199 | for ( the_node = _Chain_First( the_chain ) ; |
---|
200 | !_Chain_Is_tail( the_chain, the_node ) ; |
---|
201 | the_node = _Chain_Next( the_node ) ) { |
---|
202 | |
---|
203 | the_object = (Objects_MP_Control *) the_node; |
---|
204 | |
---|
205 | if ( the_object->name == name_to_use ) { |
---|
206 | *the_id = the_object->Object.id; |
---|
207 | _Thread_Enable_dispatch(); |
---|
208 | return OBJECTS_NAME_OR_ID_LOOKUP_SUCCESSFUL; |
---|
209 | } |
---|
210 | } |
---|
211 | } |
---|
212 | } |
---|
213 | |
---|
214 | _Thread_Enable_dispatch(); |
---|
215 | return OBJECTS_INVALID_NAME; |
---|
216 | } |
---|
217 | |
---|
218 | void _Objects_MP_Is_remote ( |
---|
219 | Objects_Information *information, |
---|
220 | Objects_Id the_id, |
---|
221 | Objects_Locations *location, |
---|
222 | Objects_Control **the_object |
---|
223 | ) |
---|
224 | { |
---|
225 | uint32_t node; |
---|
226 | Chain_Control *the_chain; |
---|
227 | Chain_Node *the_node; |
---|
228 | Objects_MP_Control *the_global_object; |
---|
229 | |
---|
230 | node = _Objects_Get_node( the_id ); |
---|
231 | |
---|
232 | /* |
---|
233 | * NOTE: The local node was search (if necessary) by |
---|
234 | * _Objects_Name_to_id_XXX before this was invoked. |
---|
235 | * |
---|
236 | * The NODE field of an object id cannot be 0 |
---|
237 | * because 0 is an invalid node number. |
---|
238 | */ |
---|
239 | |
---|
240 | if ( node == 0 || |
---|
241 | _Objects_Is_local_node( node ) || |
---|
242 | node > _Objects_Maximum_nodes || |
---|
243 | information->global_table == NULL ) { |
---|
244 | |
---|
245 | *location = OBJECTS_ERROR; |
---|
246 | *the_object = NULL; |
---|
247 | return; |
---|
248 | } |
---|
249 | |
---|
250 | _Thread_Disable_dispatch(); |
---|
251 | |
---|
252 | the_chain = &information->global_table[ node ]; |
---|
253 | |
---|
254 | for ( the_node = _Chain_First( the_chain ) ; |
---|
255 | !_Chain_Is_tail( the_chain, the_node ) ; |
---|
256 | the_node = _Chain_Next( the_node ) ) { |
---|
257 | |
---|
258 | the_global_object = (Objects_MP_Control *) the_node; |
---|
259 | |
---|
260 | if ( _Objects_Are_ids_equal( the_global_object->Object.id, the_id ) ) { |
---|
261 | _Thread_Unnest_dispatch(); |
---|
262 | *location = OBJECTS_REMOTE; |
---|
263 | *the_object = (Objects_Control *) the_global_object; |
---|
264 | return; |
---|
265 | } |
---|
266 | } |
---|
267 | |
---|
268 | _Thread_Enable_dispatch(); |
---|
269 | *location = OBJECTS_ERROR; |
---|
270 | *the_object = NULL; |
---|
271 | |
---|
272 | } |
---|
273 | |
---|