source: rtems/c/src/exec/score/src/object.c @ 9863dbf

4.104.114.84.95
Last change on this file since 9863dbf was 9863dbf, checked in by Joel Sherrill <joel.sherrill@…>, on Aug 18, 1995 at 9:42:58 PM

+ Added object type field to object id.

+ Added name pointer to Object_Control.

+ Modified Object Open and Close to address name field.

+ Removed name as separate element from Thread and Proxy Control.

+ Added parameter "object class" to calls to Initialize Information

  • Property mode set to 100644
File size: 7.8 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  Objects_Name *names;
165  unsigned32    index;
166
167  if ( name == 0 )
168    return( RTEMS_INVALID_NAME );
169
170  if ( (information->maximum != 0) &&
171       (node == RTEMS_SEARCH_ALL_NODES ||
172        node == RTEMS_SEARCH_LOCAL_NODE ||
173        _Objects_Is_local_node( node )) ) {
174    for ( names = information->name_table, index = 1;
175          index <= information->maximum;
176          index++
177         )
178      if ( name == names[ index ] ) {
179        *id = _Objects_Build_id(
180          information->the_class,
181          _Objects_Local_node,
182          index
183        );
184        return( RTEMS_SUCCESSFUL );
185      }
186  }
187
188  if ( _Objects_Is_local_node( node ) || node == RTEMS_SEARCH_LOCAL_NODE )
189    return( RTEMS_INVALID_NAME );
190
191  return ( _Objects_MP_Global_name_search( information, name, node, id ) );
192}
193
194/*PAGE
195 *
196 * _Objects_Get
197 *
198 * This routine sets the object pointer for the given
199 * object id based on the given object information structure.
200 *
201 * Input parameters:
202 *   information - pointer to entry in table for this class
203 *   id          - object id to search for
204 *   location    - address of where to store the location
205 *
206 * Output parameters:
207 *   returns - address of object if local
208 *   location    - one of the following:
209 *                  OBJECTS_ERROR  - invalid object ID
210 *                  OBJECTS_REMOTE - remote object
211 *                  OBJECTS_LOCAL  - local object
212 */
213
214Objects_Control *_Objects_Get(
215  Objects_Information *information,
216  Objects_Id                  id,
217  Objects_Locations          *location
218)
219{
220  Objects_Control *the_object;
221  unsigned32       index;
222
223  index = id - information->minimum_id;
224
225  if ( information->maximum >= index ) {
226    _Thread_Disable_dispatch();
227    if ( (the_object = information->local_table[index+1]) != NULL ) {
228      *location = OBJECTS_LOCAL;
229      return( the_object );
230    }
231    _Thread_Enable_dispatch();
232    *location = OBJECTS_ERROR;
233    return( NULL );
234  }
235  *location = OBJECTS_ERROR;
236  _Objects_MP_Is_remote( information, id, location, &the_object );
237  return the_object;
238}
239
240
241/*PAGE
242 *
243 * _Objects_Get_next
244 *
245 * Like _Objects_Get, but considers the 'id' as a "hint" and
246 * finds next valid one after that point.
247 * Mostly used for monitor and debug traversal of an object.
248 *
249 * Input parameters:
250 *   information - pointer to entry in table for this class
251 *   id          - object id to search for
252 *   location    - address of where to store the location
253 *   next_id     - address to store next id to try
254 *
255 * Output parameters:
256 *   returns     - address of object if local
257 *   location    - one of the following:
258 *                  OBJECTS_ERROR  - invalid object ID
259 *                  OBJECTS_REMOTE - remote object
260 *                  OBJECTS_LOCAL  - local object
261 *   next_id     - will contain a reasonable "next" id to continue traversal
262 *
263 * NOTE:
264 *      assumes can add '1' to an id to get to next index.
265 */
266
267Objects_Control *
268_Objects_Get_next(
269    Objects_Information *information,
270    Objects_Id           id,
271    unsigned32          *location_p,
272    Objects_Id          *next_id_p
273)
274{
275    Objects_Control *object;
276    Objects_Id       next_id;
277   
278    if (rtems_get_index(id) == RTEMS_OBJECT_ID_INITIAL_INDEX)
279        next_id = information->minimum_id;
280    else
281        next_id = id;
282
283    do {
284        /* walked off end of list? */
285        if (rtems_get_index(next_id) > information->maximum)
286        {
287            *location_p = OBJECTS_ERROR;
288            goto final;
289        }
290       
291        /* try to grab one */
292        object = _Objects_Get(information, next_id, location_p);
293
294        next_id++;
295
296    } while (*location_p != OBJECTS_LOCAL);
297
298    *next_id_p = next_id;
299    return object;
300
301final:
302    *next_id_p = RTEMS_OBJECT_ID_FINAL;
303    return 0;
304}
Note: See TracBrowser for help on using the repository browser.