1 | /* |
---|
2 | * Multiprocessing Support for the Object Handler |
---|
3 | * |
---|
4 | * |
---|
5 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
6 | * On-Line Applications Research Corporation (OAR). |
---|
7 | * All rights assigned to U.S. Government, 1994. |
---|
8 | * |
---|
9 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
10 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
11 | * notice must appear in all copies of this file and its derivatives. |
---|
12 | * |
---|
13 | * $Id$ |
---|
14 | */ |
---|
15 | |
---|
16 | #include <rtems/system.h> |
---|
17 | #include <rtems/object.h> |
---|
18 | #include <rtems/wkspace.h> |
---|
19 | #include <rtems/config.h> |
---|
20 | |
---|
21 | /*PAGE |
---|
22 | * |
---|
23 | * _Objects_MP_Handler_initialization |
---|
24 | * |
---|
25 | */ |
---|
26 | |
---|
27 | void _Objects_MP_Handler_initialization ( |
---|
28 | unsigned32 maximum_global_objects |
---|
29 | ) |
---|
30 | { |
---|
31 | |
---|
32 | if ( maximum_global_objects == 0 ) { |
---|
33 | _Chain_Initialize_empty( &_Objects_MP_Inactive_global_objects ); |
---|
34 | return; |
---|
35 | } |
---|
36 | |
---|
37 | _Chain_Initialize( |
---|
38 | &_Objects_MP_Inactive_global_objects, |
---|
39 | _Workspace_Allocate_or_fatal_error( |
---|
40 | maximum_global_objects * sizeof( Objects_MP_Control ) |
---|
41 | ), |
---|
42 | maximum_global_objects, |
---|
43 | sizeof( Objects_MP_Control ) |
---|
44 | ); |
---|
45 | |
---|
46 | } |
---|
47 | |
---|
48 | /*PAGE |
---|
49 | * |
---|
50 | * _Objects_MP_Open |
---|
51 | * |
---|
52 | */ |
---|
53 | |
---|
54 | boolean _Objects_MP_Open ( |
---|
55 | Objects_Information *information, |
---|
56 | Objects_Name the_name, |
---|
57 | Objects_Id the_id, |
---|
58 | boolean is_fatal_error |
---|
59 | ) |
---|
60 | { |
---|
61 | Objects_MP_Control *the_global_object; |
---|
62 | |
---|
63 | the_global_object = _Objects_MP_Allocate_global_object(); |
---|
64 | if ( _Objects_MP_Is_null_global_object( the_global_object ) ) { |
---|
65 | |
---|
66 | if ( is_fatal_error == FALSE ) |
---|
67 | return FALSE; |
---|
68 | |
---|
69 | rtems_fatal_error_occurred( RTEMS_TOO_MANY ); |
---|
70 | |
---|
71 | } |
---|
72 | |
---|
73 | the_global_object->Object.id = the_id; |
---|
74 | the_global_object->name = the_name; |
---|
75 | |
---|
76 | _Chain_Prepend( |
---|
77 | &information->global_table[ rtems_get_node( the_id ) ], |
---|
78 | &the_global_object->Object.Node |
---|
79 | ); |
---|
80 | |
---|
81 | return TRUE; |
---|
82 | } |
---|
83 | |
---|
84 | /*PAGE |
---|
85 | * |
---|
86 | * _Objects_MP_Close |
---|
87 | * |
---|
88 | */ |
---|
89 | |
---|
90 | void _Objects_MP_Close ( |
---|
91 | Objects_Information *information, |
---|
92 | Objects_Id the_id |
---|
93 | ) |
---|
94 | { |
---|
95 | Chain_Control *the_chain; |
---|
96 | Chain_Node *the_node; |
---|
97 | Objects_MP_Control *the_object; |
---|
98 | |
---|
99 | the_chain = &information->global_table[ rtems_get_node( the_id ) ]; |
---|
100 | |
---|
101 | for ( the_node = the_chain->first ; |
---|
102 | !_Chain_Is_tail( the_chain, the_node ) ; |
---|
103 | the_node = the_node->next ) { |
---|
104 | |
---|
105 | the_object = (Objects_MP_Control *) the_node; |
---|
106 | |
---|
107 | if ( _Objects_Are_ids_equal( the_object->Object.id, the_id ) ) { |
---|
108 | |
---|
109 | _Chain_Extract( the_node ); |
---|
110 | _Objects_MP_Free_global_object( the_object ); |
---|
111 | |
---|
112 | return; |
---|
113 | |
---|
114 | } |
---|
115 | |
---|
116 | } |
---|
117 | |
---|
118 | rtems_fatal_error_occurred( RTEMS_INVALID_ID ); |
---|
119 | |
---|
120 | |
---|
121 | } |
---|
122 | |
---|
123 | /*PAGE |
---|
124 | * |
---|
125 | * _Objects_MP_Global_name_search |
---|
126 | * |
---|
127 | */ |
---|
128 | |
---|
129 | rtems_status_code _Objects_MP_Global_name_search ( |
---|
130 | Objects_Information *information, |
---|
131 | Objects_Name the_name, |
---|
132 | unsigned32 nodes_to_search, |
---|
133 | Objects_Id *the_id |
---|
134 | ) |
---|
135 | { |
---|
136 | unsigned32 low_node; |
---|
137 | unsigned32 high_node; |
---|
138 | unsigned32 node_index; |
---|
139 | Chain_Control *the_chain; |
---|
140 | Chain_Node *the_node; |
---|
141 | Objects_MP_Control *the_object; |
---|
142 | |
---|
143 | |
---|
144 | if ( nodes_to_search > _Configuration_MP_table->maximum_nodes ) |
---|
145 | return ( RTEMS_INVALID_NODE ); |
---|
146 | |
---|
147 | if ( information->global_table == NULL ) |
---|
148 | return ( RTEMS_INVALID_NAME ); |
---|
149 | |
---|
150 | if ( nodes_to_search == RTEMS_SEARCH_ALL_NODES || |
---|
151 | nodes_to_search == RTEMS_SEARCH_OTHER_NODES ) { |
---|
152 | low_node = 1; |
---|
153 | high_node = _Configuration_MP_table->maximum_nodes; |
---|
154 | } else { |
---|
155 | low_node = |
---|
156 | high_node = nodes_to_search; |
---|
157 | } |
---|
158 | |
---|
159 | _Thread_Disable_dispatch(); |
---|
160 | |
---|
161 | for ( node_index = low_node ; node_index <= high_node ; node_index++ ) { |
---|
162 | |
---|
163 | /* |
---|
164 | * NOTE: The local node was search (if necessary) by |
---|
165 | * _Objects_Name_to_id before this was invoked. |
---|
166 | */ |
---|
167 | |
---|
168 | if ( !_Objects_Is_local_node( node_index ) ) { |
---|
169 | the_chain = &information->global_table[ node_index ]; |
---|
170 | |
---|
171 | for ( the_node = the_chain->first ; |
---|
172 | !_Chain_Is_tail( the_chain, the_node ) ; |
---|
173 | the_node = the_node->next ) { |
---|
174 | |
---|
175 | the_object = (Objects_MP_Control *) the_node; |
---|
176 | |
---|
177 | if ( the_object->name == the_name ) { |
---|
178 | *the_id = the_object->Object.id; |
---|
179 | _Thread_Enable_dispatch(); |
---|
180 | return ( RTEMS_SUCCESSFUL ); |
---|
181 | } |
---|
182 | } |
---|
183 | } |
---|
184 | } |
---|
185 | |
---|
186 | _Thread_Enable_dispatch(); |
---|
187 | return ( RTEMS_INVALID_NAME ); |
---|
188 | } |
---|
189 | |
---|
190 | /*PAGE |
---|
191 | * |
---|
192 | * _Objects_MP_Is_remote |
---|
193 | * |
---|
194 | */ |
---|
195 | |
---|
196 | void _Objects_MP_Is_remote ( |
---|
197 | Objects_Information *information, |
---|
198 | Objects_Id the_id, |
---|
199 | Objects_Locations *location, |
---|
200 | Objects_Control **the_object |
---|
201 | ) |
---|
202 | { |
---|
203 | unsigned32 node; |
---|
204 | Chain_Control *the_chain; |
---|
205 | Chain_Node *the_node; |
---|
206 | Objects_MP_Control *the_global_object; |
---|
207 | |
---|
208 | node = rtems_get_node( the_id ); |
---|
209 | |
---|
210 | /* |
---|
211 | * NOTE: The local node was search (if necessary) by |
---|
212 | * _Objects_Name_to_id before this was invoked. |
---|
213 | * |
---|
214 | * The NODE field of an object id cannot be 0 |
---|
215 | * because 0 is an invalid node number. |
---|
216 | */ |
---|
217 | |
---|
218 | if ( node == 0 || |
---|
219 | _Objects_Is_local_node( node ) || |
---|
220 | node > _Configuration_MP_table->maximum_nodes || |
---|
221 | information->global_table == NULL ) { |
---|
222 | |
---|
223 | *location = OBJECTS_ERROR; |
---|
224 | *the_object = NULL; |
---|
225 | return; |
---|
226 | } |
---|
227 | |
---|
228 | _Thread_Disable_dispatch(); |
---|
229 | |
---|
230 | the_chain = &information->global_table[ node ]; |
---|
231 | |
---|
232 | for ( the_node = the_chain->first ; |
---|
233 | !_Chain_Is_tail( the_chain, the_node ) ; |
---|
234 | the_node = the_node->next ) { |
---|
235 | |
---|
236 | the_global_object = (Objects_MP_Control *) the_node; |
---|
237 | |
---|
238 | if ( _Objects_Are_ids_equal( the_global_object->Object.id, the_id ) ) { |
---|
239 | _Thread_Unnest_dispatch(); |
---|
240 | *location = OBJECTS_REMOTE; |
---|
241 | *the_object = (Objects_Control *) the_global_object; |
---|
242 | return; |
---|
243 | } |
---|
244 | } |
---|
245 | |
---|
246 | _Thread_Enable_dispatch(); |
---|
247 | *location = OBJECTS_ERROR; |
---|
248 | *the_object = NULL; |
---|
249 | |
---|
250 | } |
---|