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

4.104.114.84.95
Last change on this file since ac7d5ef0 was ac7d5ef0, checked in by Joel Sherrill <joel.sherrill@…>, on May 11, 1995 at 5:39:37 PM

Initial revision

  • Property mode set to 100644
File size: 5.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#include <rtems/system.h>
16#include <rtems/chain.h>
17#include <rtems/config.h>
18#include <rtems/object.h>
19#include <rtems/objectmp.h>
20#include <rtems/thread.h>
21#include <rtems/wkspace.h>
22
23/*PAGE
24 *
25 *  _Objects_Handler_initialization
26 *
27 *  This routine initializes the object handler.
28 *
29 *  Input parameters:
30 *    node                   - local node
31 *    maximum_global_objects - number of configured global objects
32 *
33 *  Output parameters:  NONE
34 */
35
36void _Objects_Handler_initialization(
37  unsigned32 node,
38  unsigned32 maximum_global_objects
39)
40{
41  _Objects_Local_node = node;
42
43  _Objects_MP_Handler_initialization( maximum_global_objects );
44}
45
46/*PAGE
47 *
48 *  _Objects_Initialize_information
49 *
50 *  This routine initializes all object information related data structures.
51 *
52 *  Input parameters:
53 *    information     - object class
54 *    supports_global - TRUE if this is a global object class
55 *    maximum         - maximum objects of this class
56 *    size            - size of this object's control block
57 *
58 *  Output parameters:  NONE
59 */
60
61void _Objects_Initialize_information(
62  Objects_Information *information,
63  boolean                     supports_global,
64  unsigned32                  maximum,
65  unsigned32                  size
66)
67{
68  unsigned32       minimum_index;
69  unsigned32       index;
70  Objects_Control *the_object;
71
72  information->maximum = maximum;
73
74  if ( maximum == 0 ) minimum_index = 0;
75  else                minimum_index = 1;
76
77  information->minimum_id =
78    _Objects_Build_id( _Objects_Local_node, minimum_index );
79
80  information->maximum_id =
81    _Objects_Build_id( _Objects_Local_node, maximum );
82
83  information->local_table = _Workspace_Allocate_or_fatal_error(
84    (maximum + 1) * sizeof(Objects_Control *)
85  );
86
87  information->name_table = _Workspace_Allocate_or_fatal_error(
88    (maximum + 1) * sizeof(Objects_Name)
89  );
90
91  for ( index=0 ; index < maximum ; index++ ) {
92     information->local_table[ index ] = NULL;
93     information->name_table[ index ]  = 0;
94  }
95
96  if ( maximum == 0 ) {
97    _Chain_Initialize_empty( &information->Inactive );
98  } else {
99
100
101    _Chain_Initialize(
102      &information->Inactive,
103      _Workspace_Allocate_or_fatal_error( maximum * size ),
104      maximum,
105      size
106    );
107
108    the_object = (Objects_Control *) information->Inactive.first;
109    for ( index=1;
110          index <= maximum ;
111          index++ ) {
112      the_object->id = _Objects_Build_id( _Objects_Local_node, index );
113      the_object = (Objects_Control *) the_object->Node.next;
114    }
115
116  }
117
118 if ( supports_global == TRUE && _Configuration_Is_multiprocessing() ) {
119
120   information->global_table = _Workspace_Allocate_or_fatal_error(
121     (_Configuration_MP_table->maximum_nodes + 1) * sizeof(Chain_Control)
122   );
123
124   for ( index=1;
125         index <= _Configuration_MP_table->maximum_nodes ;
126         index++ )
127     _Chain_Initialize_empty( &information->global_table[ index ] );
128  }
129  else
130    information->global_table = NULL;
131}
132
133/*PAGE
134 *
135 *  _Objects_Name_to_id
136 *
137 *  These kernel routines search the object table(s) for the given
138 *  object name and returns the associated object id.
139 *
140 *  Input parameters:
141 *    information - object information
142 *    name        - user defined object name
143 *    node        - node indentifier (0 indicates any node)
144 *    id          - address of return ID
145 *
146 *  Output parameters:
147 *    obj_id     - object id
148 *    RTEMS_SUCCESSFUL - if successful
149 *    error code - if unsuccessful
150 */
151
152rtems_status_code _Objects_Name_to_id(
153  Objects_Information *information,
154  Objects_Name                name,
155  unsigned32                  node,
156  Objects_Id                 *id
157)
158{
159  Objects_Name *names;
160  unsigned32    index;
161
162  if ( name == 0 )
163    return( RTEMS_INVALID_NAME );
164
165  if ( (information->maximum != 0) &&
166       (node == RTEMS_SEARCH_ALL_NODES ||
167        node == RTEMS_SEARCH_LOCAL_NODE ||
168        _Objects_Is_local_node( node )) ) {
169    for ( names = information->name_table, index = 1;
170          index <= information->maximum;
171          index++
172         )
173      if ( name == names[ index ] ) {
174        *id = _Objects_Build_id( _Objects_Local_node, index );
175        return( RTEMS_SUCCESSFUL );
176      }
177  }
178
179  if ( _Objects_Is_local_node( node ) || node == RTEMS_SEARCH_LOCAL_NODE )
180    return( RTEMS_INVALID_NAME );
181
182  return ( _Objects_MP_Global_name_search( information, name, node, id ) );
183}
184
185/*PAGE
186 *
187 * _Objects_Get
188 *
189 * This routine sets the object pointer for the given
190 * object id based on the given object information structure.
191 *
192 * Input parameters:
193 *   information - pointer to entry in table for this class
194 *   id          - object id to search for
195 *   location    - address of where to store the location
196 *
197 * Output parameters:
198 *   returns - address of object if local
199 *   location    - one of the following:
200 *                  OBJECTS_ERROR  - invalid object ID
201 *                  OBJECTS_REMOTE - remote object
202 *                  OBJECTS_LOCAL  - local object
203 */
204
205Objects_Control *_Objects_Get(
206  Objects_Information *information,
207  Objects_Id                  id,
208  Objects_Locations          *location
209)
210{
211  Objects_Control *the_object;
212  unsigned32       index;
213
214  index = id - information->minimum_id;
215  if ( information->maximum >= index ) {
216    _Thread_Disable_dispatch();
217    if ( (the_object = information->local_table[index+1]) != NULL ) {
218      *location = OBJECTS_LOCAL;
219      return( the_object );
220    }
221    _Thread_Enable_dispatch();
222    *location = OBJECTS_ERROR;
223    return( NULL );
224  }
225  *location = OBJECTS_ERROR;
226  _Objects_MP_Is_remote( information, id, location, &the_object );
227  return the_object;
228}
Note: See TracBrowser for help on using the repository browser.