source: rtems/cpukit/score/src/objectgetnameasstring.c @ 2d2352b

4.115
Last change on this file since 2d2352b was 2d2352b, checked in by Sebastian Huber <sebastian.huber@…>, on 06/05/13 at 09:48:57

score: Add and use _Objects_Put()

Add and use _Objects_Put_without_thread_dispatch(). These two functions
pair with the _Objects_Get() function. This helps to introduce object
specific SMP locks to avoid lock contention.

  • Property mode set to 100644
File size: 2.3 KB
Line 
1/**
2 * @file
3 *
4 * @brief Extracts a Node from a Chain
5 *
6 * @ingroup Score
7 */
8
9/*
10 *  COPYRIGHT (c) 1989-2008.
11 *  On-Line Applications Research Corporation (OAR).
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.rtems.com/license/LICENSE.
16 */
17
18#ifdef HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22#include <rtems/system.h>
23#include <rtems/score/object.h>
24#include <rtems/score/thread.h>
25#include <stdlib.h>
26#include <ctype.h>
27#include <inttypes.h>
28
29/*
30 *  This method objects the name of an object and returns its name
31 *  in the form of a C string.  It attempts to be careful about
32 *  overflowing the user's string and about returning unprintable characters.
33 */
34
35char *_Objects_Get_name_as_string(
36  Objects_Id        id,
37  size_t            length,
38  char             *name
39)
40{
41  Objects_Information   *information;
42  const char            *s;
43  char                  *d;
44  uint32_t               i;
45  char                   lname[5];
46  Objects_Control       *the_object;
47  Objects_Locations      location;
48  Objects_Id             tmpId;
49
50  if ( length == 0 )
51    return NULL;
52
53  if ( name == NULL )
54    return NULL;
55
56  tmpId = (id == OBJECTS_ID_OF_SELF) ? _Thread_Executing->Object.id : id;
57
58  information = _Objects_Get_information_id( tmpId );
59  if ( !information )
60    return NULL;
61
62  the_object = _Objects_Get( information, tmpId, &location );
63  switch ( location ) {
64
65#if defined(RTEMS_MULTIPROCESSING)
66    case OBJECTS_REMOTE:
67      /* not supported */
68#endif
69    case OBJECTS_ERROR:
70      return NULL;
71
72    case OBJECTS_LOCAL:
73
74      #if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
75        if ( information->is_string ) {
76          s = the_object->name.name_p;
77        } else
78      #endif
79      {
80        uint32_t  u32_name = (uint32_t) the_object->name.name_u32;
81
82        lname[ 0 ] = (u32_name >> 24) & 0xff;
83        lname[ 1 ] = (u32_name >> 16) & 0xff;
84        lname[ 2 ] = (u32_name >>  8) & 0xff;
85        lname[ 3 ] = (u32_name >>  0) & 0xff;
86        lname[ 4 ] = '\0';
87        s = lname;
88      }
89
90      d = name;
91      if ( s ) {
92        for ( i=0 ; i<(length-1) && *s ; i++, s++, d++ ) {
93          *d = (isprint((unsigned char)*s)) ? *s : '*';
94        }
95      }
96      *d = '\0';
97
98      _Objects_Put( the_object );
99      return name;
100  }
101  return NULL;                  /* unreachable path */
102}
Note: See TracBrowser for help on using the repository browser.