source: rtems/cpukit/score/src/objectallocate.c @ 1c2d178

5
Last change on this file since 1c2d178 was 3899bc1a, checked in by Sebastian Huber <sebastian.huber@…>, on 11/24/18 at 10:51:28

score: Optimize object lookup

Use the maximum ID for the ID to object translation. Using the maximum
ID gets rid of an additional load from the object information in
_Objects_Get(). In addition, object lookups fail for every ID in case
the object information is cleared to zero. This makes it a bit more
robust during system startup (see new tests in spconfig02).

The local table no longer needs a NULL pointer entry at array index
zero. Adjust all the object iteration loops accordingly.

Remove Objects_Information::minimum_id since it contains only redundant
information. Add _Objects_Get_minimum_id() to get the minimum ID.

Update #3621.

  • Property mode set to 100644
File size: 2.1 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 ( information->auto_extend ) {
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 block;
72
73      block = _Objects_Get_index( the_object->id ) - OBJECTS_INDEX_MINIMUM;
74      block /= information->objects_per_block;
75
76      information->inactive_per_block[ block ]--;
77      information->inactive--;
78    }
79  }
80
81  return the_object;
82}
83
84Objects_Control *_Objects_Allocate( Objects_Information *information )
85{
86  _RTEMS_Lock_allocator();
87
88  return _Objects_Allocate_unprotected( information );
89}
Note: See TracBrowser for help on using the repository browser.