source: rtems/cpukit/score/src/objectmp.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

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