source: rtems/cpukit/score/src/objectextendinformation.c @ 9b4422a2

4.115
Last change on this file since 9b4422a2 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

  • Property mode set to 100644
File size: 7.0 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
13#if HAVE_CONFIG_H
14#include "config.h"
15#endif
16
17#include <rtems/system.h>
18#include <rtems/score/address.h>
19#include <rtems/score/chain.h>
20#include <rtems/score/object.h>
21#if defined(RTEMS_MULTIPROCESSING)
22#include <rtems/score/objectmp.h>
23#endif
24#include <rtems/score/thread.h>
25#include <rtems/score/wkspace.h>
26#include <rtems/score/sysstate.h>
27#include <rtems/score/isr.h>
28
29#include <string.h>  /* for memcpy() */
30
31/*
32 *  _Objects_Extend_information
33 *
34 *  This routine extends all object information related data structures.
35 *
36 *  Input parameters:
37 *    information     - object information table
38 *
39 *  Output parameters:  NONE
40 */
41
42void _Objects_Extend_information(
43  Objects_Information *information
44)
45{
46  Objects_Control  *the_object;
47  Chain_Control     Inactive;
48  uint32_t          block_count;
49  uint32_t          block;
50  uint32_t          index_base;
51  uint32_t          minimum_index;
52  uint32_t          index;
53  uint32_t          maximum;
54  size_t            block_size;
55  void             *new_object_block;
56  bool              do_extend;
57
58  /*
59   *  Search for a free block of indexes. If we do NOT need to allocate or
60   *  extend the block table, then we will change do_extend.
61   */
62  do_extend     = true;
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  if ( information->object_blocks == NULL )
69    block_count = 0;
70  else {
71    block_count = information->maximum / information->allocation_size;
72
73    for ( ; block < block_count; block++ ) {
74      if ( information->object_blocks[ block ] == NULL ) {
75        do_extend = false;
76        break;
77      } else
78        index_base += information->allocation_size;
79    }
80  }
81
82  maximum = (uint32_t) information->maximum + information->allocation_size;
83
84  /*
85   *  We need to limit the number of objects to the maximum number
86   *  representable in the index portion of the object Id.  In the
87   *  case of 16-bit Ids, this is only 256 object instances.
88   */
89  if ( maximum > OBJECTS_ID_FINAL_INDEX ) {
90    return;
91  }
92
93  /*
94   * Allocate the name table, and the objects and if it fails either return or
95   * generate a fatal error depending on auto-extending being active.
96   */
97  block_size = information->allocation_size * information->size;
98  if ( information->auto_extend ) {
99    new_object_block = _Workspace_Allocate( block_size );
100    if ( !new_object_block )
101      return;
102  } else {
103    new_object_block = _Workspace_Allocate_or_fatal_error( block_size );
104  }
105
106  /*
107   *  Do we need to grow the tables?
108   */
109  if ( do_extend ) {
110    ISR_Level         level;
111    void            **object_blocks;
112    uint32_t         *inactive_per_block;
113    Objects_Control **local_table;
114    void             *old_tables;
115    size_t            block_size;
116
117    /*
118     *  Growing the tables means allocating a new area, doing a copy and
119     *  updating the information table.
120     *
121     *  If the maximum is minimum we do not have a table to copy. First
122     *  time through.
123     *
124     *  The allocation has :
125     *
126     *      void            *objects[block_count];
127     *      uint32_t         inactive_count[block_count];
128     *      Objects_Control *local_table[maximum];
129     *
130     *  This is the order in memory. Watch changing the order. See the memcpy
131     *  below.
132     */
133
134    /*
135     *  Up the block count and maximum
136     */
137    block_count++;
138
139    /*
140     *  Allocate the tables and break it up.
141     */
142    block_size = block_count *
143           (sizeof(void *) + sizeof(uint32_t) + sizeof(Objects_Name *)) +
144          ((maximum + minimum_index) * sizeof(Objects_Control *));
145    object_blocks = (void**) _Workspace_Allocate( block_size );
146
147    if ( !object_blocks ) {
148      _Workspace_Free( new_object_block );
149      return;
150    }
151
152    /*
153     *  Break the block into the various sections.
154     */
155    inactive_per_block = (uint32_t *) _Addresses_Add_offset(
156        object_blocks, block_count * sizeof(void*) );
157    local_table = (Objects_Control **) _Addresses_Add_offset(
158        inactive_per_block, block_count * sizeof(uint32_t) );
159
160    /*
161     *  Take the block count down. Saves all the (block_count - 1)
162     *  in the copies.
163     */
164    block_count--;
165
166    if ( information->maximum > minimum_index ) {
167
168      /*
169       *  Copy each section of the table over. This has to be performed as
170       *  separate parts as size of each block has changed.
171       */
172
173      memcpy( object_blocks,
174              information->object_blocks,
175              block_count * sizeof(void*) );
176      memcpy( inactive_per_block,
177              information->inactive_per_block,
178              block_count * sizeof(uint32_t) );
179      memcpy( local_table,
180              information->local_table,
181              (information->maximum + minimum_index) * sizeof(Objects_Control *) );
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    object_blocks[block_count] = NULL;
196    inactive_per_block[block_count] = 0;
197
198    for ( index=index_base ;
199          index < ( information->allocation_size + index_base );
200          index++ ) {
201      local_table[ index ] = NULL;
202    }
203
204    _ISR_Disable( level );
205
206    old_tables = information->object_blocks;
207
208    information->object_blocks = object_blocks;
209    information->inactive_per_block = inactive_per_block;
210    information->local_table = local_table;
211    information->maximum = (Objects_Maximum) maximum;
212    information->maximum_id = _Objects_Build_id(
213        information->the_api,
214        information->the_class,
215        _Objects_Local_node,
216        information->maximum
217      );
218
219    _ISR_Enable( level );
220
221    _Workspace_Free( old_tables );
222
223    block_count++;
224  }
225
226  /*
227   *  Assign the new object block to the object block table.
228   */
229  information->object_blocks[ block ] = new_object_block;
230
231  /*
232   *  Initialize objects .. add to a local chain first.
233   */
234  _Chain_Initialize(
235    &Inactive,
236    information->object_blocks[ block ],
237    information->allocation_size,
238    information->size
239  );
240
241  /*
242   *  Move from the local chain, initialise, then append to the inactive chain
243   */
244  index = index_base;
245
246  while ((the_object = (Objects_Control *) _Chain_Get( &Inactive )) != NULL ) {
247
248    the_object->id = _Objects_Build_id(
249        information->the_api,
250        information->the_class,
251        _Objects_Local_node,
252        index
253      );
254
255    _Chain_Append( &information->Inactive, &the_object->Node );
256
257    index++;
258  }
259
260  information->inactive_per_block[ block ] = information->allocation_size;
261  information->inactive =
262    (Objects_Maximum)(information->inactive + information->allocation_size);
263}
Note: See TracBrowser for help on using the repository browser.