source: rtems/cpukit/score/src/objectnametoidstring.c @ 3899bc1a

5
Last change on this file since 3899bc1a 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: 1.6 KB
Line 
1/**
2 * @file
3 *
4 * @brief Object ID to Name
5 * @ingroup ScoreObject
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2010.
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
23#include <string.h>
24
25Objects_Control *_Objects_Get_by_name(
26  const Objects_Information *information,
27  const char                *name,
28  size_t                    *name_length_p,
29  Objects_Get_by_name_error *error
30)
31{
32  size_t   name_length;
33  size_t   max_name_length;
34  uint32_t index;
35
36  _Assert( _Objects_Has_string_name( information ) );
37  _Assert( _Objects_Allocator_is_owner() );
38
39  if ( name == NULL ) {
40    *error = OBJECTS_GET_BY_NAME_INVALID_NAME;
41    return NULL;
42  }
43
44  name_length = strnlen( name, information->name_length + 1 );
45  max_name_length = information->name_length;
46  if ( name_length > max_name_length ) {
47    *error = OBJECTS_GET_BY_NAME_NAME_TOO_LONG;
48    return NULL;
49  }
50
51  if ( name_length_p != NULL ) {
52    *name_length_p = name_length;
53  }
54
55  for ( index = 0; index < information->maximum; ++index ) {
56    Objects_Control *the_object;
57
58    the_object = information->local_table[ index ];
59
60    if ( the_object == NULL )
61      continue;
62
63    if ( the_object->name.name_p == NULL )
64      continue;
65
66    if ( strncmp( name, the_object->name.name_p, max_name_length ) == 0 ) {
67      return the_object;
68    }
69  }
70
71  *error = OBJECTS_GET_BY_NAME_NO_OBJECT;
72  return NULL;
73}
Note: See TracBrowser for help on using the repository browser.