source: rtems/cpukit/score/src/objectextendinformation.c @ b72e847b

4.8
Last change on this file since b72e847b was a8eed23, checked in by Ralf Corsepius <ralf.corsepius@…>, on 01/27/05 at 05:57:05

Include config.h.

  • Property mode set to 100644
File size: 7.6 KB
Line 
1/*
2 *  Object Handler
3 *
4 *
5 *  COPYRIGHT (c) 1989-1999.
6 *  On-Line Applications Research Corporation (OAR).
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.rtems.com/license/LICENSE.
11 *
12 *  $Id$
13 */
14
15#if HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include <rtems/system.h>
20#include <rtems/score/address.h>
21#include <rtems/score/chain.h>
22#include <rtems/score/object.h>
23#if defined(RTEMS_MULTIPROCESSING)
24#include <rtems/score/objectmp.h>
25#endif
26#include <rtems/score/thread.h>
27#include <rtems/score/wkspace.h>
28#include <rtems/score/sysstate.h>
29#include <rtems/score/isr.h>
30
31#include <string.h>  /* for memcpy() */
32
33/*PAGE
34 *
35 *  _Objects_Extend_information
36 *
37 *  This routine extends all object information related data structures.
38 *
39 *  Input parameters:
40 *    information     - object information table
41 *
42 *  Output parameters:  NONE
43 */
44
45void _Objects_Extend_information(
46  Objects_Information *information
47)
48{
49  Objects_Control  *the_object;
50  void             *name_area;
51  Chain_Control     Inactive;
52  uint32_t          block_count;
53  uint32_t          block;
54  uint32_t          index_base;
55  uint32_t          minimum_index;
56  uint32_t          index;
57
58  /*
59   *  Search for a free block of indexes. The block variable ends up set
60   *  to block_count + 1 if the table needs to be extended.
61   */
62
63  minimum_index = _Objects_Get_index( information->minimum_id );
64  index_base    = minimum_index;
65  block         = 0;
66
67  if ( information->maximum < minimum_index )
68    block_count = 0;
69  else {
70    block_count = information->maximum / information->allocation_size;
71
72    for ( ; block < block_count; block++ ) {
73      if ( information->object_blocks[ block ] == NULL )
74        break;
75      else
76        index_base += information->allocation_size;
77    }
78  }
79
80  /*
81   *  If the index_base is the maximum we need to grow the tables.
82   */
83
84  if (index_base >= information->maximum ) {
85    ISR_Level         level;
86    void            **object_blocks;
87    Objects_Name     *name_table;
88    uint32_t         *inactive_per_block;
89    Objects_Control **local_table;
90    uint32_t          maximum;
91    void             *old_tables;
92
93    /*
94     *  Growing the tables means allocating a new area, doing a copy and
95     *  updating the information table.
96     *
97     *  If the maximum is minimum we do not have a table to copy. First
98     *  time through.
99     *
100     *  The allocation has :
101     *
102     *      void            *objects[block_count];
103     *      uint32_t         inactive_count[block_count];
104     *      Objects_Name    *name_table[block_count];
105     *      Objects_Control *local_table[maximum];
106     *
107     *  This is the order in memory. Watch changing the order. See the memcpy
108     *  below.
109     */
110
111    /*
112     *  Up the block count and maximum
113     */
114
115    block_count++;
116
117    maximum = information->maximum + information->allocation_size;
118
119    /*
120     *  Allocate the tables and break it up.
121     */
122
123    if ( information->auto_extend ) {
124      object_blocks = (void**)
125        _Workspace_Allocate(
126          block_count *
127             (sizeof(void *) + sizeof(uint32_t  ) + sizeof(Objects_Name *)) +
128          ((maximum + minimum_index) * sizeof(Objects_Control *))
129          );
130
131      if ( !object_blocks )
132        return;
133    }
134    else {
135      object_blocks = (void**)
136        _Workspace_Allocate_or_fatal_error(
137          block_count *
138             (sizeof(void *) + sizeof(uint32_t  ) + sizeof(Objects_Name *)) +
139          ((maximum + minimum_index) * sizeof(Objects_Control *))
140        );
141    }
142
143    /*
144     *  Break the block into the various sections.
145     *
146     */
147
148    inactive_per_block = (uint32_t   *) _Addresses_Add_offset(
149        object_blocks, block_count * sizeof(void*) );
150    name_table = (Objects_Name *) _Addresses_Add_offset(
151        inactive_per_block, block_count * sizeof(uint32_t  ) );
152    local_table = (Objects_Control **) _Addresses_Add_offset(
153        name_table, block_count * sizeof(Objects_Name *) );
154
155    /*
156     *  Take the block count down. Saves all the (block_count - 1)
157     *  in the copies.
158     */
159
160    block_count--;
161
162    if ( information->maximum > minimum_index ) {
163
164      /*
165       *  Copy each section of the table over. This has to be performed as
166       *  separate parts as size of each block has changed.
167       */
168
169      memcpy( object_blocks,
170              information->object_blocks,
171              block_count * sizeof(void*) );
172      memcpy( inactive_per_block,
173              information->inactive_per_block,
174              block_count * sizeof(uint32_t  ) );
175      memcpy( name_table,
176              information->name_table,
177              block_count * sizeof(Objects_Name *) );
178      memcpy( local_table,
179              information->local_table,
180              (information->maximum + minimum_index) * sizeof(Objects_Control *) );
181    }
182    else {
183
184      /*
185       *  Deal with the special case of the 0 to minimum_index
186       */
187      for ( index = 0; index < minimum_index; index++ ) {
188        local_table[ index ] = NULL;
189      }
190    }
191
192    /*
193     *  Initialise the new entries in the table.
194     */
195
196    object_blocks[block_count] = NULL;
197    inactive_per_block[block_count] = 0;
198    name_table[block_count] = NULL;
199
200    for ( index=index_base ;
201          index < ( information->allocation_size + index_base );
202          index++ ) {
203      local_table[ index ] = NULL;
204    }
205
206    _ISR_Disable( level );
207
208    old_tables = information->object_blocks;
209
210    information->object_blocks = object_blocks;
211    information->inactive_per_block = inactive_per_block;
212    information->name_table = name_table;
213    information->local_table = local_table;
214    information->maximum = maximum;
215    information->maximum_id = _Objects_Build_id(
216        information->the_api,
217        information->the_class,
218        _Objects_Local_node,
219        information->maximum
220      );
221
222    _ISR_Enable( level );
223
224    if ( old_tables )
225      _Workspace_Free( old_tables );
226
227    block_count++;
228  }
229
230  /*
231   *  Allocate the name table, and the objects
232   */
233
234  if ( information->auto_extend ) {
235    information->object_blocks[ block ] =
236      _Workspace_Allocate(
237        (information->allocation_size * information->name_length) +
238        (information->allocation_size * information->size)
239      );
240
241    if ( !information->object_blocks[ block ] )
242      return;
243  }
244  else {
245    information->object_blocks[ block ] =
246      _Workspace_Allocate_or_fatal_error(
247        (information->allocation_size * information->name_length) +
248        (information->allocation_size * information->size)
249      );
250  }
251
252  name_area = (Objects_Name *) _Addresses_Add_offset(
253    information->object_blocks[ block ],
254    (information->allocation_size * information->size)
255  );
256  information->name_table[ block ] = name_area;
257
258  /*
259   *  Initialize objects .. add to a local chain first.
260   */
261
262  _Chain_Initialize(
263    &Inactive,
264    information->object_blocks[ block ],
265    information->allocation_size,
266    information->size
267  );
268
269  /*
270   *  Move from the local chain, initialise, then append to the inactive chain
271   */
272
273  index = index_base;
274
275  while ( (the_object = (Objects_Control *) _Chain_Get( &Inactive ) ) != NULL ) {
276
277    the_object->id = _Objects_Build_id(
278        information->the_api,
279        information->the_class,
280        _Objects_Local_node,
281        index
282      );
283
284    the_object->name = (void *) name_area;
285
286    name_area = _Addresses_Add_offset( name_area, information->name_length );
287
288    _Chain_Append( &information->Inactive, &the_object->Node );
289
290    index++;
291  }
292
293  information->inactive_per_block[ block ] = information->allocation_size;
294  information->inactive += information->allocation_size;
295}
Note: See TracBrowser for help on using the repository browser.