source: rtems/cpukit/score/src/objectmp.c @ 61380a54

4.115
Last change on this file since 61380a54 was 61380a54, checked in by Sebastian Huber <sebastian.huber@…>, on 01/20/11 at 08:16:15

2011-01-20 Sebastian Huber <sebastian.huber@…>

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