source: rtems/cpukit/score/src/object.c @ b06e68ef

4.104.114.84.95
Last change on this file since b06e68ef was b06e68ef, checked in by Joel Sherrill <joel.sherrill@…>, on 08/17/95 at 19:51:51

Numerous miscellaneous features incorporated from Tony Bennett
(tbennett@…) including the following major additions:

+ variable length messages
+ named devices
+ debug monitor
+ association tables/variables

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