source: rtems/cpukit/score/src/objectallocate.c @ 21275b58

Last change on this file since 21275b58 was 21275b58, checked in by Sebastian Huber <sebastian.huber@…>, on Nov 22, 2018 at 6:14:51 PM

score: Static Objects_Information initialization

Statically allocate the objects information together with the initial
set of objects either via <rtems/confdefs.h>. Provide default object
informations with zero objects via librtemscpu.a. This greatly
simplifies the workspace size estimate. RTEMS applications which do not
use the unlimited objects option are easier to debug since all objects
reside now in statically allocated objects of the right types.

Close #3621.

  • Property mode set to 100644
File size: 2.3 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief Allocate Object
5 *  @ingroup ScoreObject
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-1999.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems/score/objectimpl.h>
22#include <rtems/score/assert.h>
23#include <rtems/score/chainimpl.h>
24#include <rtems/score/sysstate.h>
25
26static Objects_Control *_Objects_Get_inactive(
27  Objects_Information *information
28)
29{
30  return (Objects_Control *) _Chain_Get_unprotected( &information->Inactive );
31}
32
33Objects_Control *_Objects_Allocate_unprotected(
34  Objects_Information *information
35)
36{
37  Objects_Control *the_object;
38
39  _Assert(
40    _Objects_Allocator_is_owner()
41      || !_System_state_Is_up( _System_state_Get() )
42  );
43
44  /*
45   *  If the application is using the optional manager stubs and
46   *  still attempts to create the object, the information block
47   *  should be all zeroed out because it is in the BSS.  So let's
48   *  check that code for this manager is even present.
49   */
50  if ( information->object_size == 0 )
51    return NULL;
52
53  /*
54   *  OK.  The manager should be initialized and configured to have objects.
55   *  With any luck, it is safe to attempt to allocate an object.
56   */
57  the_object = _Objects_Get_inactive( information );
58
59  if ( _Objects_Is_auto_extend( information ) ) {
60    /*
61     *  If the list is empty then we are out of objects and need to
62     *  extend information base.
63     */
64
65    if ( the_object == NULL ) {
66      _Objects_Extend_information( information );
67      the_object = _Objects_Get_inactive( information );
68    }
69
70    if ( the_object != NULL ) {
71      Objects_Maximum objects_per_block;
72      Objects_Maximum block;
73
74      objects_per_block = information->objects_per_block;
75      block = _Objects_Get_index( the_object->id ) - OBJECTS_INDEX_MINIMUM;
76
77      if ( block > objects_per_block ) {
78        block /= objects_per_block;
79
80        information->inactive_per_block[ block ]--;
81        information->inactive--;
82      }
83    }
84  }
85
86  return the_object;
87}
88
89Objects_Control *_Objects_Allocate( Objects_Information *information )
90{
91  _RTEMS_Lock_allocator();
92
93  return _Objects_Allocate_unprotected( information );
94}
Note: See TracBrowser for help on using the repository browser.