source: rtems/cpukit/score/src/objectmp.c @ 03f2154e

4.104.114.84.95
Last change on this file since 03f2154e was 03f2154e, checked in by Joel Sherrill <joel.sherrill@…>, on 04/22/97 at 17:20:27

headers updated to reflect new style copyright notice as part
of switching to the modified GNU GPL.

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