summaryrefslogtreecommitdiffstats
path: root/cpukit/score/src/object.c
blob: 71c365fa1e5fd3c3f0a3eba27eb623c68c7491dd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/*
 *  Object Handler
 *
 *
 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
 *  On-Line Applications Research Corporation (OAR).
 *  All rights assigned to U.S. Government, 1994.
 *
 *  This material may be reproduced by or for the U.S. Government pursuant
 *  to the copyright license under the clause at DFARS 252.227-7013.  This
 *  notice must appear in all copies of this file and its derivatives.
 *
 *  $Id$
 */
#include <rtems/system.h>
#include <rtems/chain.h>
#include <rtems/config.h>
#include <rtems/object.h>
#include <rtems/objectmp.h>
#include <rtems/thread.h>
#include <rtems/wkspace.h>

/*PAGE
 *
 *  _Objects_Handler_initialization
 *
 *  This routine initializes the object handler.
 *
 *  Input parameters:
 *    node                   - local node
 *    maximum_global_objects - number of configured global objects
 *
 *  Output parameters:  NONE
 */

void _Objects_Handler_initialization(
  unsigned32 node,
  unsigned32 maximum_global_objects
)
{
  _Objects_Local_node = node;

  _Objects_MP_Handler_initialization( maximum_global_objects );
}

/*PAGE
 *
 *  _Objects_Initialize_information
 *
 *  This routine initializes all object information related data structures.
 *
 *  Input parameters:
 *    information     - object class
 *    supports_global - TRUE if this is a global object class
 *    maximum         - maximum objects of this class
 *    size            - size of this object's control block
 *
 *  Output parameters:  NONE
 */

void _Objects_Initialize_information(
  Objects_Information *information,
  boolean                     supports_global,
  unsigned32                  maximum,
  unsigned32                  size
)
{
  unsigned32       minimum_index;
  unsigned32       index;
  Objects_Control *the_object;

  information->maximum = maximum;

  if ( maximum == 0 ) minimum_index = 0;
  else                minimum_index = 1;

  information->minimum_id =
    _Objects_Build_id( _Objects_Local_node, minimum_index );

  information->maximum_id =
    _Objects_Build_id( _Objects_Local_node, maximum );

  information->local_table = _Workspace_Allocate_or_fatal_error(
    (maximum + 1) * sizeof(Objects_Control *)
  );

  information->name_table = _Workspace_Allocate_or_fatal_error(
    (maximum + 1) * sizeof(Objects_Name)
  );

  for ( index=0 ; index < maximum ; index++ ) {
     information->local_table[ index ] = NULL;
     information->name_table[ index ]  = 0;
  }

  if ( maximum == 0 ) {
    _Chain_Initialize_empty( &information->Inactive );
  } else {


    _Chain_Initialize(
      &information->Inactive,
      _Workspace_Allocate_or_fatal_error( maximum * size ),
      maximum,
      size
    );

    the_object = (Objects_Control *) information->Inactive.first;
    for ( index=1;
          index <= maximum ;
          index++ ) {
      the_object->id = _Objects_Build_id( _Objects_Local_node, index );
      the_object = (Objects_Control *) the_object->Node.next;
    }

  }

 if ( supports_global == TRUE && _Configuration_Is_multiprocessing() ) {

   information->global_table = _Workspace_Allocate_or_fatal_error(
     (_Configuration_MP_table->maximum_nodes + 1) * sizeof(Chain_Control)
   );

   for ( index=1;
         index <= _Configuration_MP_table->maximum_nodes ;
         index++ )
     _Chain_Initialize_empty( &information->global_table[ index ] );
  }
  else
    information->global_table = NULL;
}

/*PAGE
 *
 *  _Objects_Name_to_id
 *
 *  These kernel routines search the object table(s) for the given
 *  object name and returns the associated object id.
 *
 *  Input parameters:
 *    information - object information
 *    name        - user defined object name
 *    node        - node indentifier (0 indicates any node)
 *    id          - address of return ID
 *
 *  Output parameters:
 *    obj_id     - object id
 *    RTEMS_SUCCESSFUL - if successful
 *    error code - if unsuccessful
 */

rtems_status_code _Objects_Name_to_id(
  Objects_Information *information,
  Objects_Name                name,
  unsigned32                  node,
  Objects_Id                 *id
)
{
  Objects_Name *names;
  unsigned32    index;

  if ( name == 0 )
    return( RTEMS_INVALID_NAME );

  if ( (information->maximum != 0) &&
       (node == RTEMS_SEARCH_ALL_NODES ||
        node == RTEMS_SEARCH_LOCAL_NODE ||
        _Objects_Is_local_node( node )) ) {
    for ( names = information->name_table, index = 1;
          index <= information->maximum;
          index++
         )
      if ( name == names[ index ] ) {
        *id = _Objects_Build_id( _Objects_Local_node, index );
        return( RTEMS_SUCCESSFUL );
      }
  }

  if ( _Objects_Is_local_node( node ) || node == RTEMS_SEARCH_LOCAL_NODE )
    return( RTEMS_INVALID_NAME );

  return ( _Objects_MP_Global_name_search( information, name, node, id ) );
}

/*PAGE
 *
 * _Objects_Get
 *
 * This routine sets the object pointer for the given
 * object id based on the given object information structure.
 *
 * Input parameters:
 *   information - pointer to entry in table for this class
 *   id          - object id to search for
 *   location    - address of where to store the location
 *
 * Output parameters:
 *   returns - address of object if local
 *   location    - one of the following:
 *                  OBJECTS_ERROR  - invalid object ID
 *                  OBJECTS_REMOTE - remote object
 *                  OBJECTS_LOCAL  - local object
 */

Objects_Control *_Objects_Get(
  Objects_Information *information,
  Objects_Id                  id,
  Objects_Locations          *location
)
{
  Objects_Control *the_object;
  unsigned32       index;

  index = id - information->minimum_id;
  if ( information->maximum >= index ) {
    _Thread_Disable_dispatch();
    if ( (the_object = information->local_table[index+1]) != NULL ) {
      *location = OBJECTS_LOCAL;
      return( the_object );
    }
    _Thread_Enable_dispatch();
    *location = OBJECTS_ERROR;
    return( NULL );
  }
  *location = OBJECTS_ERROR;
  _Objects_MP_Is_remote( information, id, location, &the_object );
  return the_object;
}