source: rtems/cpukit/score/src/objectextendinformation.c @ 5472ad41

4.115
Last change on this file since 5472ad41 was 64adc13, checked in by Joel Sherrill <joel.sherrill@…>, on 07/24/11 at 23:55:15

2011-07-24 Joel Sherrill <joel.sherrill@…>

  • ftpd/ftpd.c, libcsupport/src/geteuid.c, libcsupport/src/getgroups.c, libcsupport/src/getpgrp.c, libcsupport/src/getpid.c, libcsupport/src/getppid.c, libcsupport/src/setpgid.c, libcsupport/src/setsid.c, libcsupport/src/utsname.c, libmisc/stackchk/check.c, posix/include/rtems/posix/mqueue.h, posix/inline/rtems/posix/cond.inl, posix/inline/rtems/posix/mqueue.inl, posix/inline/rtems/posix/mutex.inl, posix/inline/rtems/posix/pthread.inl, posix/inline/rtems/posix/semaphore.inl, posix/inline/rtems/posix/timer.inl, posix/src/alarm.c, posix/src/barrierattrdestroy.c, posix/src/barrierattrgetpshared.c, posix/src/barrierattrinit.c, posix/src/barrierattrsetpshared.c, posix/src/cleanuppop.c, posix/src/cleanuppush.c, posix/src/clockgetcpuclockid.c, posix/src/clockgetenableattr.c, posix/src/clockgetres.c, posix/src/clockgettime.c, posix/src/clocksetenableattr.c, posix/src/clocksettime.c, posix/src/cond.c, posix/src/condattrdestroy.c, posix/src/condattrgetpshared.c, posix/src/condattrinit.c, posix/src/condattrsetpshared.c, posix/src/condbroadcast.c, posix/src/conddefaultattributes.c, posix/src/conddestroy.c, posix/src/condinit.c, posix/src/condsignal.c, posix/src/condsignalsupp.c, posix/src/condtimedwait.c, posix/src/condwait.c, posix/src/condwaitsupp.c, posix/src/keygetspecific.c, posix/src/keyrundestructors.c, posix/src/keysetspecific.c, posix/src/mprotect.c, posix/src/mqueue.c, posix/src/mqueuecreatesupp.c, posix/src/mqueuedeletesupp.c, posix/src/mqueuegetattr.c, posix/src/mqueuenotify.c, posix/src/mqueuereceive.c, posix/src/mqueuesend.c, posix/src/mqueuesendsupp.c, posix/src/mqueuesetattr.c, posix/src/mqueuetimedreceive.c, posix/src/mqueuetimedsend.c, posix/src/mqueuetranslatereturncode.c, posix/src/mqueueunlink.c, posix/src/mutex.c, posix/src/mutexattrdestroy.c, posix/src/mutexattrgetprioceiling.c, posix/src/mutexattrgetprotocol.c, posix/src/mutexattrgetpshared.c, posix/src/mutexattrinit.c, posix/src/mutexattrsetprioceiling.c, posix/src/mutexattrsetprotocol.c, posix/src/mutexattrsetpshared.c, posix/src/mutexdestroy.c, posix/src/mutexgetprioceiling.c, posix/src/mutexinit.c, posix/src/mutexlock.c, posix/src/mutexlocksupp.c, posix/src/mutexsetprioceiling.c, posix/src/mutextimedlock.c, posix/src/mutextrylock.c, posix/src/mutexunlock.c, posix/src/nanosleep.c, posix/src/psignal.c, posix/src/psignalchecksignal.c, posix/src/psignalclearprocesssignals.c, posix/src/psignalclearsignals.c, posix/src/psignalsetprocesssignals.c, posix/src/psignalunblockthread.c, posix/src/pthreadinitthreads.c, posix/src/rwlockattrdestroy.c, posix/src/rwlockattrgetpshared.c, posix/src/rwlockattrinit.c, posix/src/rwlockattrsetpshared.c, posix/src/semaphore.c, posix/src/semaphoredeletesupp.c, posix/src/semaphorenametoid.c, posix/src/semaphorewaitsupp.c, posix/src/semclose.c, posix/src/semdestroy.c, posix/src/semgetvalue.c, posix/src/seminit.c, posix/src/semopen.c, posix/src/sempost.c, posix/src/semtimedwait.c, posix/src/semtrywait.c, posix/src/semunlink.c, posix/src/semwait.c, posix/src/sysconf.c, posix/src/testcancel.c, posix/src/ualarm.c, rtems/src/clockgetuptime.c, rtems/src/clockset.c, rtems/src/clocksetnsecshandler.c, rtems/src/clocktick.c, rtems/src/clocktodtoseconds.c, rtems/src/clocktodvalidate.c, rtems/src/dpmem.c, rtems/src/dpmemcreate.c, rtems/src/dpmemdelete.c, rtems/src/dpmemexternal2internal.c, rtems/src/dpmemident.c, rtems/src/dpmeminternal2external.c, rtems/src/event.c, rtems/src/eventmp.c, rtems/src/eventreceive.c, rtems/src/eventseize.c, rtems/src/eventsend.c, rtems/src/eventsurrender.c, rtems/src/eventtimeout.c, rtems/src/mp.c, rtems/src/msg.c, rtems/src/msgmp.c, rtems/src/msgqallocate.c, rtems/src/msgqbroadcast.c, rtems/src/msgqcreate.c, rtems/src/msgqdelete.c, rtems/src/msgqflush.c, rtems/src/msgqgetnumberpending.c, rtems/src/msgqident.c, rtems/src/msgqreceive.c, rtems/src/msgqtranslatereturncode.c, rtems/src/msgqurgent.c, rtems/src/part.c, rtems/src/partcreate.c, rtems/src/partdelete.c, rtems/src/partgetbuffer.c, rtems/src/partident.c, rtems/src/partmp.c, rtems/src/partreturnbuffer.c, rtems/src/ratemon.c, rtems/src/ratemoncancel.c, rtems/src/ratemoncreate.c, rtems/src/ratemondelete.c, rtems/src/ratemongetstatistics.c, rtems/src/ratemongetstatus.c, rtems/src/ratemonident.c, rtems/src/ratemonperiod.c, rtems/src/ratemonresetstatistics.c, rtems/src/ratemontimeout.c, rtems/src/region.c, rtems/src/regioncreate.c, rtems/src/regiondelete.c, rtems/src/regionextend.c, rtems/src/regiongetfreeinfo.c, rtems/src/regiongetinfo.c, rtems/src/regiongetsegment.c, rtems/src/regiongetsegmentsize.c, rtems/src/regionident.c, rtems/src/regionmp.c, rtems/src/regionprocessqueue.c, rtems/src/regionresizesegment.c, rtems/src/regionreturnsegment.c, rtems/src/rtemsobjectgetclassicname.c, rtems/src/rtemstimer.c, rtems/src/sem.c, rtems/src/semcreate.c, rtems/src/semdelete.c, rtems/src/semflush.c, rtems/src/semident.c, rtems/src/semmp.c, rtems/src/semobtain.c, rtems/src/semrelease.c, rtems/src/semtranslatereturncode.c, rtems/src/signal.c, rtems/src/signalcatch.c, rtems/src/signalmp.c, rtems/src/signalsend.c, rtems/src/taskcreate.c, rtems/src/taskdelete.c, rtems/src/taskgetnote.c, rtems/src/taskident.c, rtems/src/taskinitusers.c, rtems/src/taskissuspended.c, rtems/src/taskmp.c, rtems/src/taskrestart.c, rtems/src/taskresume.c, rtems/src/tasks.c, rtems/src/tasksetnote.c, rtems/src/tasksetpriority.c, rtems/src/taskstart.c, rtems/src/tasksuspend.c, rtems/src/taskwakeafter.c, rtems/src/taskwakewhen.c, rtems/src/timercancel.c, rtems/src/timercreate.c, rtems/src/timerdelete.c, rtems/src/timerfireafter.c, rtems/src/timerfirewhen.c, rtems/src/timergetinfo.c, rtems/src/timerident.c, rtems/src/timerreset.c, rtems/src/timerserverfireafter.c, rtems/src/timerserverfirewhen.c, sapi/src/debug.c, sapi/src/extension.c, sapi/src/posixapi.c, sapi/src/rtemsapi.c, score/src/apiext.c, score/src/chain.c, score/src/corebarrier.c, score/src/corebarrierrelease.c, score/src/corebarrierwait.c, score/src/coremsgbroadcast.c, score/src/coremsgclose.c, score/src/coremsgflush.c, score/src/coremsgflushsupp.c, score/src/coremsgflushwait.c, score/src/coremsginsert.c, score/src/coremsgseize.c, score/src/coremsgsubmit.c, score/src/coremutex.c, score/src/coremutexflush.c, score/src/coremutexseize.c, score/src/corerwlock.c, score/src/corerwlockobtainread.c, score/src/corerwlockobtainwrite.c, score/src/corerwlockrelease.c, score/src/coresem.c, score/src/coresemflush.c, score/src/coresemsurrender.c, score/src/corespinlock.c, score/src/corespinlockrelease.c, score/src/corespinlockwait.c, score/src/coretod.c, score/src/coretodset.c, score/src/coretodtickle.c, score/src/heap.c, score/src/interr.c, score/src/mpci.c, score/src/objectallocate.c, score/src/objectextendinformation.c, score/src/objectfree.c, score/src/objectget.c, score/src/objectgetisr.c, score/src/objectgetnext.c, score/src/objectgetnoprotection.c, score/src/objectinitializeinformation.c, score/src/objectmp.c, score/src/objectnametoid.c, score/src/objectnametoidstring.c, score/src/objectshrinkinformation.c, score/src/rbtree.c, score/src/threaddelayended.c, score/src/threadhandler.c, score/src/threadinitialize.c, score/src/threadloadenv.c, score/src/threadmp.c, score/src/threadq.c, score/src/threadqdequeue.c, score/src/threadqdequeuefifo.c, score/src/threadqdequeuepriority.c, score/src/threadqenqueue.c, score/src/threadqenqueuefifo.c, score/src/threadqenqueuepriority.c, score/src/threadqextract.c, score/src/threadqextractfifo.c, score/src/threadqextractpriority.c, score/src/threadqextractwithproxy.c, score/src/threadqfirst.c, score/src/threadqfirstfifo.c, score/src/threadqfirstpriority.c, score/src/threadqflush.c, score/src/threadqrequeue.c, score/src/threadstackallocate.c, score/src/threadstartmultitasking.c, score/src/watchdog.c, score/src/watchdogadjust.c, score/src/watchdoginsert.c, score/src/watchdogremove.c, score/src/watchdogtickle.c: Remove /*PAGE markers which were interpreted by a long dead print script.
  • 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 *  $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/*
34 *  _Objects_Extend_information
35 *
36 *  This routine extends all object information related data structures.
37 *
38 *  Input parameters:
39 *    information     - object information table
40 *
41 *  Output parameters:  NONE
42 */
43
44void _Objects_Extend_information(
45  Objects_Information *information
46)
47{
48  Objects_Control  *the_object;
49  Chain_Control     Inactive;
50  uint32_t          block_count;
51  uint32_t          block;
52  uint32_t          index_base;
53  uint32_t          minimum_index;
54  uint32_t          index;
55  uint32_t          maximum;
56  size_t            block_size;
57  void             *new_object_block;
58  bool              do_extend;
59
60  /*
61   *  Search for a free block of indexes. If we do NOT need to allocate or
62   *  extend the block table, then we will change do_extend.
63   */
64  do_extend     = true;
65  minimum_index = _Objects_Get_index( information->minimum_id );
66  index_base    = minimum_index;
67  block         = 0;
68
69  /* if ( information->maximum < minimum_index ) */
70  if ( information->object_blocks == NULL )
71    block_count = 0;
72  else {
73    block_count = information->maximum / information->allocation_size;
74
75    for ( ; block < block_count; block++ ) {
76      if ( information->object_blocks[ block ] == NULL ) {
77        do_extend = false;
78        break;
79      } else
80        index_base += information->allocation_size;
81    }
82  }
83
84  maximum = (uint32_t) information->maximum + information->allocation_size;
85
86  /*
87   *  We need to limit the number of objects to the maximum number
88   *  representable in the index portion of the object Id.  In the
89   *  case of 16-bit Ids, this is only 256 object instances.
90   */
91  if ( maximum > OBJECTS_ID_FINAL_INDEX ) {
92    return;
93  }
94
95  /*
96   * Allocate the name table, and the objects and if it fails either return or
97   * generate a fatal error depending on auto-extending being active.
98   */
99  block_size = information->allocation_size * information->size;
100  if ( information->auto_extend ) {
101    new_object_block = _Workspace_Allocate( block_size );
102    if ( !new_object_block )
103      return;
104  } else {
105    new_object_block = _Workspace_Allocate_or_fatal_error( block_size );
106  }
107
108  /*
109   *  Do we need to grow the tables?
110   */
111  if ( do_extend ) {
112    ISR_Level         level;
113    void            **object_blocks;
114    uint32_t         *inactive_per_block;
115    Objects_Control **local_table;
116    void             *old_tables;
117    size_t            block_size;
118
119    /*
120     *  Growing the tables means allocating a new area, doing a copy and
121     *  updating the information table.
122     *
123     *  If the maximum is minimum we do not have a table to copy. First
124     *  time through.
125     *
126     *  The allocation has :
127     *
128     *      void            *objects[block_count];
129     *      uint32_t         inactive_count[block_count];
130     *      Objects_Control *local_table[maximum];
131     *
132     *  This is the order in memory. Watch changing the order. See the memcpy
133     *  below.
134     */
135
136    /*
137     *  Up the block count and maximum
138     */
139    block_count++;
140
141    /*
142     *  Allocate the tables and break it up.
143     */
144    block_size = block_count *
145           (sizeof(void *) + sizeof(uint32_t) + sizeof(Objects_Name *)) +
146          ((maximum + minimum_index) * sizeof(Objects_Control *));
147    object_blocks = (void**) _Workspace_Allocate( block_size );
148
149    if ( !object_blocks ) {
150      _Workspace_Free( new_object_block );
151      return;
152    }
153
154    /*
155     *  Break the block into the various sections.
156     */
157    inactive_per_block = (uint32_t *) _Addresses_Add_offset(
158        object_blocks, block_count * sizeof(void*) );
159    local_table = (Objects_Control **) _Addresses_Add_offset(
160        inactive_per_block, block_count * sizeof(uint32_t) );
161
162    /*
163     *  Take the block count down. Saves all the (block_count - 1)
164     *  in the copies.
165     */
166    block_count--;
167
168    if ( information->maximum > minimum_index ) {
169
170      /*
171       *  Copy each section of the table over. This has to be performed as
172       *  separate parts as size of each block has changed.
173       */
174
175      memcpy( object_blocks,
176              information->object_blocks,
177              block_count * sizeof(void*) );
178      memcpy( inactive_per_block,
179              information->inactive_per_block,
180              block_count * sizeof(uint32_t) );
181      memcpy( local_table,
182              information->local_table,
183              (information->maximum + minimum_index) * sizeof(Objects_Control *) );
184    } else {
185
186      /*
187       *  Deal with the special case of the 0 to minimum_index
188       */
189      for ( index = 0; index < minimum_index; index++ ) {
190        local_table[ index ] = NULL;
191      }
192    }
193
194    /*
195     *  Initialise the new entries in the table.
196     */
197    object_blocks[block_count] = NULL;
198    inactive_per_block[block_count] = 0;
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->local_table = local_table;
213    information->maximum = (Objects_Maximum) maximum;
214    information->maximum_id = _Objects_Build_id(
215        information->the_api,
216        information->the_class,
217        _Objects_Local_node,
218        information->maximum
219      );
220
221    _ISR_Enable( level );
222
223    _Workspace_Free( old_tables );
224
225    block_count++;
226  }
227
228  /*
229   *  Assign the new object block to the object block table.
230   */
231  information->object_blocks[ block ] = new_object_block;
232
233  /*
234   *  Initialize objects .. add to a local chain first.
235   */
236  _Chain_Initialize(
237    &Inactive,
238    information->object_blocks[ block ],
239    information->allocation_size,
240    information->size
241  );
242
243  /*
244   *  Move from the local chain, initialise, then append to the inactive chain
245   */
246  index = index_base;
247
248  while ((the_object = (Objects_Control *) _Chain_Get( &Inactive )) != NULL ) {
249
250    the_object->id = _Objects_Build_id(
251        information->the_api,
252        information->the_class,
253        _Objects_Local_node,
254        index
255      );
256
257    _Chain_Append( &information->Inactive, &the_object->Node );
258
259    index++;
260  }
261
262  information->inactive_per_block[ block ] = information->allocation_size;
263  information->inactive =
264    (Objects_Maximum)(information->inactive + information->allocation_size);
265}
Note: See TracBrowser for help on using the repository browser.