source: rtems/c/src/exec/score/src/object.c @ 63edbb3f

4.104.114.84.95
Last change on this file since 63edbb3f was 61361688, checked in by Joel Sherrill <joel.sherrill@…>, on 08/22/95 at 13:56:54

Modified object name to id translation loop to make it easier to
incorporate variable length object names. Previously the algorithm
scanned an array of 4-byte names for a match. Now it scans the
object table, grabs a pointer to the name, and then compares it
if the object is active and has a name.

  • Property mode set to 100644
File size: 7.9 KB
Line 
1/*
2 *  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/chain.h>
18#include <rtems/config.h>
19#include <rtems/object.h>
20#include <rtems/objectmp.h>
21#include <rtems/thread.h>
22#include <rtems/wkspace.h>
23
24/*PAGE
25 *
26 *  _Objects_Handler_initialization
27 *
28 *  This routine initializes the object handler.
29 *
30 *  Input parameters:
31 *    node                   - local node
32 *    maximum_global_objects - number of configured global objects
33 *
34 *  Output parameters:  NONE
35 */
36
37void _Objects_Handler_initialization(
38  unsigned32 node,
39  unsigned32 maximum_global_objects
40)
41{
42  _Objects_Local_node = node;
43
44  _Objects_MP_Handler_initialization( maximum_global_objects );
45}
46
47/*PAGE
48 *
49 *  _Objects_Initialize_information
50 *
51 *  This routine initializes all object information related data structures.
52 *
53 *  Input parameters:
54 *    information     - object information table
55 *    the_class       - object class
56 *    supports_global - TRUE if this is a global object class
57 *    maximum         - maximum objects of this class
58 *    size            - size of this object's control block
59 *
60 *  Output parameters:  NONE
61 */
62
63void _Objects_Initialize_information(
64  Objects_Information *information,
65  Objects_Classes      the_class,
66  boolean              supports_global,
67  unsigned32           maximum,
68  unsigned32           size
69)
70{
71  unsigned32       minimum_index;
72  unsigned32       index;
73  Objects_Control *the_object;
74
75  information->maximum   = maximum;
76  information->the_class = the_class;
77
78  if ( maximum == 0 ) minimum_index = 0;
79  else                minimum_index = 1;
80
81  information->minimum_id =
82    _Objects_Build_id( the_class, _Objects_Local_node, minimum_index );
83
84  information->maximum_id =
85    _Objects_Build_id( the_class, _Objects_Local_node, maximum );
86
87  information->local_table = _Workspace_Allocate_or_fatal_error(
88    (maximum + 1) * sizeof(Objects_Control *)
89  );
90
91  information->name_table = _Workspace_Allocate_or_fatal_error(
92    (maximum + 1) * sizeof(Objects_Name)
93  );
94
95  for ( index=0 ; index < maximum ; index++ ) {
96     information->local_table[ index ] = NULL;
97     information->name_table[ index ]  = 0;
98  }
99
100  if ( maximum == 0 ) {
101    _Chain_Initialize_empty( &information->Inactive );
102  } else {
103
104
105    _Chain_Initialize(
106      &information->Inactive,
107      _Workspace_Allocate_or_fatal_error( maximum * size ),
108      maximum,
109      size
110    );
111
112    the_object = (Objects_Control *) information->Inactive.first;
113    for ( index=1;
114          index <= maximum ;
115          index++ ) {
116      the_object->id =
117        _Objects_Build_id( the_class, _Objects_Local_node, index );
118      the_object = (Objects_Control *) the_object->Node.next;
119    }
120
121  }
122
123 if ( supports_global == TRUE && _Configuration_Is_multiprocessing() ) {
124
125   information->global_table = _Workspace_Allocate_or_fatal_error(
126     (_Configuration_MP_table->maximum_nodes + 1) * sizeof(Chain_Control)
127   );
128
129   for ( index=1;
130         index <= _Configuration_MP_table->maximum_nodes ;
131         index++ )
132     _Chain_Initialize_empty( &information->global_table[ index ] );
133  }
134  else
135    information->global_table = NULL;
136}
137
138/*PAGE
139 *
140 *  _Objects_Name_to_id
141 *
142 *  These kernel routines search the object table(s) for the given
143 *  object name and returns the associated object id.
144 *
145 *  Input parameters:
146 *    information - object information
147 *    name        - user defined object name
148 *    node        - node indentifier (0 indicates any node)
149 *    id          - address of return ID
150 *
151 *  Output parameters:
152 *    obj_id     - object id
153 *    RTEMS_SUCCESSFUL - if successful
154 *    error code - if unsuccessful
155 */
156
157rtems_status_code _Objects_Name_to_id(
158  Objects_Information *information,
159  Objects_Name                name,
160  unsigned32                  node,
161  Objects_Id                 *id
162)
163{
164  boolean           search_local_node;
165  Objects_Control **objects;
166  Objects_Control  *the_object;
167  unsigned32        index;
168
169  if ( name == 0 )
170    return( RTEMS_INVALID_NAME );
171
172  search_local_node = FALSE;
173
174  if ( information->maximum != 0 &&
175      (node == RTEMS_SEARCH_ALL_NODES || node == RTEMS_SEARCH_LOCAL_NODE ||
176      _Objects_Is_local_node( node ) ) )
177   search_local_node = TRUE;
178
179  if ( search_local_node ) {
180    objects = information->local_table;
181
182    for ( index = 1; index <= information->maximum; index++ ) {
183
184      the_object = objects[ index ];
185
186      if ( !the_object || !the_object->name )
187        continue;
188
189      if ( name == *the_object->name ) {
190        *id = the_object->id;
191        return( RTEMS_SUCCESSFUL );
192      }
193    }
194  }
195
196  if ( _Objects_Is_local_node( node ) || node == RTEMS_SEARCH_LOCAL_NODE )
197    return( RTEMS_INVALID_NAME );
198
199  return ( _Objects_MP_Global_name_search( information, name, node, id ) );
200}
201
202/*PAGE
203 *
204 * _Objects_Get
205 *
206 * This routine sets the object pointer for the given
207 * object id based on the given object information structure.
208 *
209 * Input parameters:
210 *   information - pointer to entry in table for this class
211 *   id          - object id to search for
212 *   location    - address of where to store the location
213 *
214 * Output parameters:
215 *   returns - address of object if local
216 *   location    - one of the following:
217 *                  OBJECTS_ERROR  - invalid object ID
218 *                  OBJECTS_REMOTE - remote object
219 *                  OBJECTS_LOCAL  - local object
220 */
221
222Objects_Control *_Objects_Get(
223  Objects_Information *information,
224  Objects_Id                  id,
225  Objects_Locations          *location
226)
227{
228  Objects_Control *the_object;
229  unsigned32       index;
230
231  index = id - information->minimum_id;
232
233  if ( information->maximum >= index ) {
234    _Thread_Disable_dispatch();
235    if ( (the_object = information->local_table[index+1]) != NULL ) {
236      *location = OBJECTS_LOCAL;
237      return( the_object );
238    }
239    _Thread_Enable_dispatch();
240    *location = OBJECTS_ERROR;
241    return( NULL );
242  }
243  *location = OBJECTS_ERROR;
244  _Objects_MP_Is_remote( information, id, location, &the_object );
245  return the_object;
246}
247
248
249/*PAGE
250 *
251 * _Objects_Get_next
252 *
253 * Like _Objects_Get, but considers the 'id' as a "hint" and
254 * finds next valid one after that point.
255 * Mostly used for monitor and debug traversal of an object.
256 *
257 * Input parameters:
258 *   information - pointer to entry in table for this class
259 *   id          - object id to search for
260 *   location    - address of where to store the location
261 *   next_id     - address to store next id to try
262 *
263 * Output parameters:
264 *   returns     - address of object if local
265 *   location    - one of the following:
266 *                  OBJECTS_ERROR  - invalid object ID
267 *                  OBJECTS_REMOTE - remote object
268 *                  OBJECTS_LOCAL  - local object
269 *   next_id     - will contain a reasonable "next" id to continue traversal
270 *
271 * NOTE:
272 *      assumes can add '1' to an id to get to next index.
273 */
274
275Objects_Control *
276_Objects_Get_next(
277    Objects_Information *information,
278    Objects_Id           id,
279    unsigned32          *location_p,
280    Objects_Id          *next_id_p
281)
282{
283    Objects_Control *object;
284    Objects_Id       next_id;
285   
286    if (rtems_get_index(id) == RTEMS_OBJECT_ID_INITIAL_INDEX)
287        next_id = information->minimum_id;
288    else
289        next_id = id;
290
291    do {
292        /* walked off end of list? */
293        if (rtems_get_index(next_id) > information->maximum)
294        {
295            *location_p = OBJECTS_ERROR;
296            goto final;
297        }
298       
299        /* try to grab one */
300        object = _Objects_Get(information, next_id, location_p);
301
302        next_id++;
303
304    } while (*location_p != OBJECTS_LOCAL);
305
306    *next_id_p = next_id;
307    return object;
308
309final:
310    *next_id_p = RTEMS_OBJECT_ID_FINAL;
311    return 0;
312}
Note: See TracBrowser for help on using the repository browser.