source: rtems/cpukit/score/src/objectmp.c @ 358bd740

5
Last change on this file since 358bd740 was 358bd740, checked in by Sebastian Huber <sebastian.huber@…>, on 02/03/16 at 11:41:02

score: Avoid SCORE_EXTERN

Delete SCORE_INIT. This finally removes the

some.h:

#ifndef SOME_XYZ_EXTERN
#define SOME_XYZ_EXTERN extern
#endif
SOME_XYZ_EXTERN type xyz;

some_xyz.c:

#define SOME_XYZ_EXTERN
#include <some.h>

pattern in favour of

some.h:

extern type xyz;

some_xyz.c

#include <some.h>
type xyz;

Update #2559.

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