[PATCH 03/14] Remove RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES

Sebastian Huber sebastian.huber at embedded-brains.de
Mon Oct 29 09:03:12 UTC 2018


Enable support for string objects names unconditionally.  Add const
qualifier throughout.  Split _Objects_Namespace_remove() into
_Objects_Namespace_remove_u32() and _Objects_Namespace_remove_string()
to avoid an unnecessary dependency on _Workspace_Free().

Update #2514.
---
 cpukit/include/rtems/posix/mqueueimpl.h        |  6 ++-
 cpukit/include/rtems/posix/semaphoreimpl.h     |  6 ++-
 cpukit/include/rtems/score/object.h            | 16 +-----
 cpukit/include/rtems/score/objectimpl.h        | 74 +++++++++++++-------------
 cpukit/posix/src/key.c                         |  4 +-
 cpukit/posix/src/ptimer.c                      |  4 +-
 cpukit/posix/src/semaphoredeletesupp.c         |  2 +-
 cpukit/score/src/objectclose.c                 |  6 +--
 cpukit/score/src/objectgetnameasstring.c       | 17 ++----
 cpukit/score/src/objectidtoname.c              |  6 +--
 cpukit/score/src/objectinitializeinformation.c |  4 +-
 cpukit/score/src/objectnamespaceremove.c       | 34 ++++++------
 cpukit/score/src/objectnametoidstring.c        |  2 -
 cpukit/score/src/objectsetname.c               | 12 ++---
 14 files changed, 85 insertions(+), 108 deletions(-)

diff --git a/cpukit/include/rtems/posix/mqueueimpl.h b/cpukit/include/rtems/posix/mqueueimpl.h
index 6813a3ef88..28381ad54b 100644
--- a/cpukit/include/rtems/posix/mqueueimpl.h
+++ b/cpukit/include/rtems/posix/mqueueimpl.h
@@ -156,8 +156,10 @@ RTEMS_INLINE_ROUTINE void _POSIX_Message_queue_Namespace_remove (
   POSIX_Message_queue_Control *the_mq
 )
 {
-  _Objects_Namespace_remove( 
-    &_POSIX_Message_queue_Information, &the_mq->Object );
+  _Objects_Namespace_remove_string(
+    &_POSIX_Message_queue_Information,
+    &the_mq->Object
+  );
 }
 
 RTEMS_INLINE_ROUTINE POSIX_Message_queue_Control *
diff --git a/cpukit/include/rtems/posix/semaphoreimpl.h b/cpukit/include/rtems/posix/semaphoreimpl.h
index fd17743699..5ae6a300fa 100644
--- a/cpukit/include/rtems/posix/semaphoreimpl.h
+++ b/cpukit/include/rtems/posix/semaphoreimpl.h
@@ -107,8 +107,10 @@ RTEMS_INLINE_ROUTINE void _POSIX_Semaphore_Namespace_remove (
   POSIX_Semaphore_Control *the_semaphore
 )
 {
-  _Objects_Namespace_remove( 
-    &_POSIX_Semaphore_Information, &the_semaphore->Object );
+  _Objects_Namespace_remove_string(
+    &_POSIX_Semaphore_Information,
+    &the_semaphore->Object
+  );
 }
 
 RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control *_POSIX_Semaphore_Get_by_name(
diff --git a/cpukit/include/rtems/score/object.h b/cpukit/include/rtems/score/object.h
index 6789c61fea..adafcaa72d 100644
--- a/cpukit/include/rtems/score/object.h
+++ b/cpukit/include/rtems/score/object.h
@@ -36,16 +36,6 @@ extern "C" {
  */
 /**@{*/
 
-#if defined(RTEMS_POSIX_API)
-  /**
-   *  This macro is defined when an API is enabled that requires the
-   *  use of strings for object names.  Since the Classic API uses
-   *  32-bit unsigned integers and not strings, this allows us to
-   *  disable this in the smallest RTEMS configuratinos.
-   */
-  #define RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES
-#endif
-
 /**
  * @defgroup ScoreCPU CPU Architecture Support
  *
@@ -67,10 +57,8 @@ extern "C" {
  *  object names.
  */
 typedef union {
-  #if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
-    /** This is a pointer to a string name. */
-    const char *name_p;
-  #endif
+  /** This is a pointer to a string name. */
+  const char *name_p;
   /** This is the actual 32-bit "raw" integer name. */
   uint32_t    name_u32;
 } Objects_Name;
diff --git a/cpukit/include/rtems/score/objectimpl.h b/cpukit/include/rtems/score/objectimpl.h
index cc5820785c..1bef14b116 100644
--- a/cpukit/include/rtems/score/objectimpl.h
+++ b/cpukit/include/rtems/score/objectimpl.h
@@ -130,6 +130,8 @@ typedef struct {
   Objects_Id        maximum_id;
   /** This is the maximum number of objects in this class. */
   Objects_Maximum   maximum;
+  /** This is true if names are strings. */
+  bool              is_string;
   /** This is the true if unlimited objects in this class. */
   bool              auto_extend;
   /** This is the number of objects in a block. */
@@ -146,10 +148,6 @@ typedef struct {
   uint32_t         *inactive_per_block;
   /** This is a table to the chain of inactive object memory blocks. */
   void            **object_blocks;
-  #if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
-    /** This is true if names are strings. */
-    bool              is_string;
-  #endif
   /** This is the maximum length of names. */
   uint16_t          name_length;
   #if defined(RTEMS_MULTIPROCESSING)
@@ -685,22 +683,31 @@ size_t _Objects_Name_to_string(
  *  @retval If successful, true is returned.  Otherwise false is returned.
  */
 bool _Objects_Set_name(
-  Objects_Information *information,
-  Objects_Control     *the_object,
-  const char          *name
+  const Objects_Information *information,
+  Objects_Control           *the_object,
+  const char                *name
 );
 
 /**
- *  @brief Removes object from namespace.
+ * @brief Removes object with a 32-bit integer name from its namespace.
  *
- *  This function removes @a the_object from the namespace.
+ * @param[in] information The corresponding object information table.
+ * @param[in] the_object The object.
+ */
+void _Objects_Namespace_remove_u32(
+  const Objects_Information *information,
+  Objects_Control           *the_object
+);
+
+/**
+ * @brief Removes object with a string name from its namespace.
  *
- *  @param[in] information points to an Object Information Table.
- *  @param[in] the_object is a pointer to an object.
+ * @param[in] information The corresponding object information table.
+ * @param[in] the_object The object.
  */
-void _Objects_Namespace_remove(
-  Objects_Information  *information,
-  Objects_Control      *the_object
+void _Objects_Namespace_remove_string(
+  const Objects_Information *information,
+  Objects_Control           *the_object
 );
 
 /**
@@ -713,8 +720,8 @@ void _Objects_Namespace_remove(
  *  @param[in] the_object is a pointer to an object
  */
 void _Objects_Close(
-  Objects_Information  *information,
-  Objects_Control      *the_object
+  const Objects_Information *information,
+  Objects_Control           *the_object
 );
 
 /**
@@ -828,9 +835,9 @@ RTEMS_INLINE_ROUTINE bool _Objects_Are_ids_equal(
  */
 
 RTEMS_INLINE_ROUTINE void _Objects_Set_local_object(
-  Objects_Information *information,
-  uint32_t             index,
-  Objects_Control     *the_object
+  const Objects_Information *information,
+  uint32_t                   index,
+  Objects_Control           *the_object
 )
 {
   /*
@@ -838,10 +845,7 @@ RTEMS_INLINE_ROUTINE void _Objects_Set_local_object(
    *  where the Id is known to be good.  Therefore, this should NOT
    *  occur in normal situations.
    */
-  #if defined(RTEMS_DEBUG)
-    if ( index > information->maximum )
-      return;
-  #endif
+  _Assert( index <= information->maximum );
 
   information->local_table[ index ] = the_object;
 }
@@ -861,8 +865,8 @@ RTEMS_INLINE_ROUTINE void _Objects_Set_local_object(
  */
 
 RTEMS_INLINE_ROUTINE void _Objects_Invalidate_Id(
-  Objects_Information  *information,
-  Objects_Control      *the_object
+  const Objects_Information *information,
+  Objects_Control           *the_object
 )
 {
   _Assert( information != NULL );
@@ -910,12 +914,12 @@ RTEMS_INLINE_ROUTINE void _Objects_Open(
  * @param[in] name is the name of the object to make accessible
  */
 RTEMS_INLINE_ROUTINE void _Objects_Open_u32(
-  Objects_Information *information,
-  Objects_Control     *the_object,
-  uint32_t             name
+  const Objects_Information *information,
+  Objects_Control           *the_object,
+  uint32_t                   name
 )
 {
-  /* ASSERT: information->is_string == false */
+  _Assert( !information->is_string );
   the_object->name.name_u32 = name;
 
   _Objects_Set_local_object(
@@ -934,15 +938,13 @@ RTEMS_INLINE_ROUTINE void _Objects_Open_u32(
  * @param[in] name is the name of the object to make accessible
  */
 RTEMS_INLINE_ROUTINE void _Objects_Open_string(
-  Objects_Information *information,
-  Objects_Control     *the_object,
-  const char          *name
+  const Objects_Information *information,
+  Objects_Control           *the_object,
+  const char                *name
 )
 {
-  #if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
-    /* ASSERT: information->is_string */
-    the_object->name.name_p = name;
-  #endif
+  _Assert( information->is_string );
+  the_object->name.name_p = name;
 
   _Objects_Set_local_object(
     information,
diff --git a/cpukit/posix/src/key.c b/cpukit/posix/src/key.c
index 48a52dfb34..71c202926e 100644
--- a/cpukit/posix/src/key.c
+++ b/cpukit/posix/src/key.c
@@ -142,8 +142,8 @@ static void _POSIX_Keys_Manager_initialization(void)
                                 /* maximum objects of this class */
     sizeof( POSIX_Keys_Control ),
                                 /* size of this object's control block */
-    true,                       /* true if names for this object are strings */
-    _POSIX_PATH_MAX,            /* maximum length of each object's name */
+    false,                      /* true if names for this object are strings */
+    0,                          /* maximum length of each object's name */
     NULL                        /* Proxy extraction support callout */
   );
 
diff --git a/cpukit/posix/src/ptimer.c b/cpukit/posix/src/ptimer.c
index de3645cc14..e938d50058 100644
--- a/cpukit/posix/src/ptimer.c
+++ b/cpukit/posix/src/ptimer.c
@@ -66,8 +66,8 @@ static void _POSIX_Timer_Manager_initialization(void)
                                 /* maximum objects of this class */
     sizeof( POSIX_Timer_Control ),
                                 /* size of this object's control block */
-    true,                       /* true if names for this object are strings */
-    _POSIX_PATH_MAX,            /* maximum length of each object's name */
+    false,                      /* true if names for this object are strings */
+    0,                          /* maximum length of each object's name */
     NULL                        /* Proxy extraction support callout */
   );
 }
diff --git a/cpukit/posix/src/semaphoredeletesupp.c b/cpukit/posix/src/semaphoredeletesupp.c
index dbcfebfd65..69452369fb 100644
--- a/cpukit/posix/src/semaphoredeletesupp.c
+++ b/cpukit/posix/src/semaphoredeletesupp.c
@@ -23,7 +23,7 @@
 void _POSIX_Semaphore_Delete( POSIX_Semaphore_Control *the_semaphore )
 {
   if ( !the_semaphore->linked && !the_semaphore->open_count ) {
-    _Objects_Close( &_POSIX_Semaphore_Information, &the_semaphore->Object );
+    _Objects_Invalidate_Id( &_POSIX_Semaphore_Information, &the_semaphore->Object );
     _POSIX_Semaphore_Destroy( &the_semaphore->Semaphore );
     _POSIX_Semaphore_Free( the_semaphore );
   }
diff --git a/cpukit/score/src/objectclose.c b/cpukit/score/src/objectclose.c
index 52eb10c60b..e5ee4b5d46 100644
--- a/cpukit/score/src/objectclose.c
+++ b/cpukit/score/src/objectclose.c
@@ -21,11 +21,11 @@
 #include <rtems/score/objectimpl.h>
 
 void _Objects_Close(
-  Objects_Information  *information,
-  Objects_Control      *the_object
+  const Objects_Information *information,
+  Objects_Control           *the_object
 )
 {
   _Objects_Invalidate_Id( information, the_object );
 
-  _Objects_Namespace_remove( information, the_object );
+  _Objects_Namespace_remove_u32( information, the_object );
 }
diff --git a/cpukit/score/src/objectgetnameasstring.c b/cpukit/score/src/objectgetnameasstring.c
index f23b1599e1..ed6a73c0f8 100644
--- a/cpukit/score/src/objectgetnameasstring.c
+++ b/cpukit/score/src/objectgetnameasstring.c
@@ -45,12 +45,9 @@ size_t _Objects_Name_to_string(
   char       *d;
   size_t      i;
 
-#if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
   if ( is_string ) {
     s = name.name_p;
-  } else
-#endif
-  {
+  } else {
     lname[ 0 ] = (name.name_u32 >> 24) & 0xff;
     lname[ 1 ] = (name.name_u32 >> 16) & 0xff;
     lname[ 2 ] = (name.name_u32 >>  8) & 0xff;
@@ -93,10 +90,10 @@ char *_Objects_Get_name_as_string(
   char             *name
 )
 {
-  Objects_Information   *information;
-  Objects_Control       *the_object;
-  ISR_lock_Context       lock_context;
-  Objects_Id             tmpId;
+  const Objects_Information *information;
+  const Objects_Control     *the_object;
+  ISR_lock_Context           lock_context;
+  Objects_Id                 tmpId;
 
   if ( length == 0 )
     return NULL;
@@ -117,11 +114,7 @@ char *_Objects_Get_name_as_string(
 
   _Objects_Name_to_string(
     the_object->name,
-#if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
     information->is_string,
-#else
-    false,
-#endif
     name,
     length
   );
diff --git a/cpukit/score/src/objectidtoname.c b/cpukit/score/src/objectidtoname.c
index aff3296738..85eb409a8e 100644
--- a/cpukit/score/src/objectidtoname.c
+++ b/cpukit/score/src/objectidtoname.c
@@ -40,10 +40,8 @@ Objects_Name_or_id_lookup_errors _Objects_Id_to_name (
   if ( !information )
     return OBJECTS_INVALID_ID;
 
-  #if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
-    if ( information->is_string )
-      return OBJECTS_INVALID_ID;
-  #endif
+  if ( information->is_string )
+    return OBJECTS_INVALID_ID;
 
   the_object = _Objects_Get(
     tmpId,
diff --git a/cpukit/score/src/objectinitializeinformation.c b/cpukit/score/src/objectinitializeinformation.c
index 8b1b88db07..23c7819bfa 100644
--- a/cpukit/score/src/objectinitializeinformation.c
+++ b/cpukit/score/src/objectinitializeinformation.c
@@ -49,9 +49,7 @@ void _Objects_Do_initialize_information(
   information->inactive_per_block = 0;
   information->object_blocks      = 0;
   information->inactive           = 0;
-  #if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
-    information->is_string        = is_string;
-  #endif
+  information->is_string          = is_string;
 
   /*
    *  Set the maximum value to 0. It will be updated when objects are
diff --git a/cpukit/score/src/objectnamespaceremove.c b/cpukit/score/src/objectnamespaceremove.c
index 6698737254..fb7b54c532 100644
--- a/cpukit/score/src/objectnamespaceremove.c
+++ b/cpukit/score/src/objectnamespaceremove.c
@@ -22,24 +22,24 @@
 #include <rtems/score/objectimpl.h>
 #include <rtems/score/wkspace.h>
 
-void _Objects_Namespace_remove(
-  Objects_Information  *information,
-  Objects_Control      *the_object
+void _Objects_Namespace_remove_u32(
+  const Objects_Information *information,
+  Objects_Control           *the_object
 )
 {
-  #if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
-    /*
-     *  If this is a string format name, then free the memory.
-     */
-    if ( information->is_string )
-       _Workspace_Free( (void *)the_object->name.name_p );
-  #endif
-
-  /*
-   * Clear out either format.
-   */
-  #if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
-    the_object->name.name_p   = NULL;
-  #endif
+  _Assert( !information->is_string );
   the_object->name.name_u32 = 0;
 }
+
+void _Objects_Namespace_remove_string(
+  const Objects_Information *information,
+  Objects_Control           *the_object
+)
+{
+  void *name;
+
+  _Assert( information->is_string );
+  name = the_object->name.name_p;
+  the_object->name.name_p = NULL;
+  _Workspace_Free( name );
+}
diff --git a/cpukit/score/src/objectnametoidstring.c b/cpukit/score/src/objectnametoidstring.c
index bd4b4a9ead..dd69f8a9ea 100644
--- a/cpukit/score/src/objectnametoidstring.c
+++ b/cpukit/score/src/objectnametoidstring.c
@@ -22,7 +22,6 @@
 
 #include <string.h>
 
-#if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
 Objects_Control *_Objects_Get_by_name(
   const Objects_Information *information,
   const char                *name,
@@ -72,4 +71,3 @@ Objects_Control *_Objects_Get_by_name(
   *error = OBJECTS_GET_BY_NAME_NO_OBJECT;
   return NULL;
 }
-#endif
diff --git a/cpukit/score/src/objectsetname.c b/cpukit/score/src/objectsetname.c
index c699570209..227de515ec 100644
--- a/cpukit/score/src/objectsetname.c
+++ b/cpukit/score/src/objectsetname.c
@@ -24,9 +24,9 @@
 #include <string.h>
 
 bool _Objects_Set_name(
-  Objects_Information *information,
-  Objects_Control     *the_object,
-  const char          *name
+  const Objects_Information *information,
+  Objects_Control           *the_object,
+  const char                *name
 )
 {
   size_t                 length;
@@ -35,7 +35,6 @@ bool _Objects_Set_name(
   s      = name;
   length = strnlen( name, information->name_length );
 
-#if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
   if ( information->is_string ) {
     char *d;
 
@@ -49,16 +48,13 @@ bool _Objects_Set_name(
     strncpy( d, name, length );
     d[length] = '\0';
     the_object->name.name_p = d;
-  } else
-#endif
-  {
+  } else {
     the_object->name.name_u32 =  _Objects_Build_name(
       ((length)     ? s[ 0 ] : ' '),
       ((length > 1) ? s[ 1 ] : ' '),
       ((length > 2) ? s[ 2 ] : ' '),
       ((length > 3) ? s[ 3 ] : ' ')
     );
-
   }
 
   return true;
-- 
2.16.4




More information about the devel mailing list