[PATCH 1/3] score: Remove Objects_Information::auto_extend

Sebastian Huber sebastian.huber at embedded-brains.de
Tue Dec 11 15:41:08 UTC 2018


Use Objects_Information::objects_per_block to provide this information.
Add and use _Objects_Is_auto_extend().

Update #3621.
---
 cpukit/include/rtems/score/objectimpl.h        | 27 ++++++++++++++++++++----
 cpukit/rtems/src/rtemsobjectgetclassinfo.c     |  2 +-
 cpukit/score/src/objectallocate.c              |  2 +-
 cpukit/score/src/objectextendinformation.c     | 29 ++++++++++++++++----------
 cpukit/score/src/objectfree.c                  |  2 +-
 cpukit/score/src/objectinitializeinformation.c | 25 +++++++++++-----------
 testsuites/samples/unlimited/test1.c           |  8 +++----
 7 files changed, 61 insertions(+), 34 deletions(-)

diff --git a/cpukit/include/rtems/score/objectimpl.h b/cpukit/include/rtems/score/objectimpl.h
index e32533c8f3..bbf32fcd80 100644
--- a/cpukit/include/rtems/score/objectimpl.h
+++ b/cpukit/include/rtems/score/objectimpl.h
@@ -126,7 +126,12 @@ typedef struct {
   Objects_Control **local_table;
   /** This is the number of objects on the Inactive list. */
   Objects_Maximum   inactive;
-  /** This is the number of objects in a block. */
+  /**
+   * @brief This is the number of objects in a block if the automatic extension
+   * is enabled.
+   *
+   * This member is zero if the automatic extension is disabled.
+   */
   Objects_Maximum   objects_per_block;
   /** This is the size in bytes of each object instance. */
   uint16_t          object_size;
@@ -137,8 +142,6 @@ typedef struct {
    * (OBJECTS_NO_STRING_NAME).
    */
   uint16_t          name_length;
-  /** This is the true if unlimited objects in this class. */
-  bool              auto_extend;
   /** This is the chain of inactive control blocks. */
   Chain_Control     Inactive;
   /** This is the number of inactive objects per block. */
@@ -747,7 +750,7 @@ RTEMS_INLINE_ROUTINE Objects_Maximum _Objects_Extend_size(
   const Objects_Information *information
 )
 {
-  return information->auto_extend ? information->objects_per_block : 0;
+  return information->objects_per_block;
 }
 
 /**
@@ -858,6 +861,22 @@ RTEMS_INLINE_ROUTINE Objects_Maximum _Objects_Get_maximum_index(
   return _Objects_Get_index( information->maximum_id );
 }
 
+/**
+ * @brief Returns true if the automatic object extension (unlimited objects) is
+ * enabled, otherwise false.
+ *
+ * @param[in] information The object information.
+ *
+ * @retval true The automatic object extension (unlimited objects) is enabled.
+ * @retval false Otherwise.
+ */
+RTEMS_INLINE_ROUTINE Objects_Maximum _Objects_Is_auto_extend(
+  const Objects_Information *information
+)
+{
+  return information->objects_per_block != 0;
+}
+
 /**
  * This function sets the pointer to the local_table object
  * referenced by the index.
diff --git a/cpukit/rtems/src/rtemsobjectgetclassinfo.c b/cpukit/rtems/src/rtemsobjectgetclassinfo.c
index a2b07e36ea..e0f5ab63a1 100644
--- a/cpukit/rtems/src/rtemsobjectgetclassinfo.c
+++ b/cpukit/rtems/src/rtemsobjectgetclassinfo.c
@@ -46,7 +46,7 @@ rtems_status_code rtems_object_get_class_information(
    */
   info->minimum_id  = _Objects_Get_minimum_id( obj_info->maximum_id );
   info->maximum_id  = obj_info->maximum_id;
-  info->auto_extend = obj_info->auto_extend;
+  info->auto_extend = _Objects_Is_auto_extend( obj_info );
   info->maximum     = _Objects_Get_maximum_index( obj_info );
 
   for ( unallocated=0, i=1 ; i <= info->maximum ; i++ )
diff --git a/cpukit/score/src/objectallocate.c b/cpukit/score/src/objectallocate.c
index 2f991477da..9213cf8eb7 100644
--- a/cpukit/score/src/objectallocate.c
+++ b/cpukit/score/src/objectallocate.c
@@ -56,7 +56,7 @@ Objects_Control *_Objects_Allocate_unprotected(
    */
   the_object = _Objects_Get_inactive( information );
 
-  if ( information->auto_extend ) {
+  if ( _Objects_Is_auto_extend( information ) ) {
     /*
      *  If the list is empty then we are out of objects and need to
      *  extend information base.
diff --git a/cpukit/score/src/objectextendinformation.c b/cpukit/score/src/objectextendinformation.c
index 4e55bbc636..59a03ebbb4 100644
--- a/cpukit/score/src/objectextendinformation.c
+++ b/cpukit/score/src/objectextendinformation.c
@@ -49,6 +49,7 @@ void _Objects_Extend_information(
   uint32_t          index_base;
   uint32_t          index_end;
   uint32_t          index;
+  Objects_Maximum   extend_count;
   Objects_Maximum   old_maximum;
   uint32_t          new_maximum;
   size_t            object_block_size;
@@ -62,7 +63,10 @@ void _Objects_Extend_information(
   );
 
   api_class_and_node = information->maximum_id & ~OBJECTS_INDEX_MASK;
-  old_maximum = _Objects_Get_maximum_index( information );
+
+  if ( _Objects_Is_auto_extend( information ) ) {
+  } else {
+  }
 
   /*
    *  Search for a free block of indexes. If we do NOT need to allocate or
@@ -72,22 +76,26 @@ void _Objects_Extend_information(
   index_base    = 0;
   block         = 0;
 
-  if ( information->object_blocks == NULL )
+  if ( information->object_blocks == NULL ) {
+    extend_count = _Objects_Get_maximum_index( information );
+    old_maximum = 0;
     block_count = 0;
-  else {
-    block_count = old_maximum / information->objects_per_block;
+  } else {
+    extend_count = information->objects_per_block;
+    old_maximum = _Objects_Get_maximum_index( information );
+    block_count = old_maximum / extend_count;
 
     for ( ; block < block_count; block++ ) {
       if ( information->object_blocks[ block ] == NULL ) {
         do_extend = false;
         break;
       } else
-        index_base += information->objects_per_block;
+        index_base += extend_count;
     }
   }
-  index_end = index_base + information->objects_per_block;
 
-  new_maximum = (uint32_t) old_maximum + information->objects_per_block;
+  new_maximum = (uint32_t) old_maximum + extend_count;
+  index_end = index_base + extend_count;
 
   /*
    *  We need to limit the number of objects to the maximum number
@@ -102,9 +110,8 @@ void _Objects_Extend_information(
    * Allocate the name table, and the objects and if it fails either return or
    * generate a fatal error depending on auto-extending being active.
    */
-  object_block_size = information->objects_per_block
-    * information->object_size;
-  if ( information->auto_extend ) {
+  object_block_size = extend_count * information->object_size;
+  if ( _Objects_Is_auto_extend( information ) ) {
     new_object_block = _Workspace_Allocate( object_block_size );
     if ( !new_object_block )
       return;
@@ -155,7 +162,7 @@ void _Objects_Extend_information(
     table_size = object_blocks_size
       + local_table_size
       + block_count * sizeof( *inactive_per_block );
-    if ( information->auto_extend ) {
+    if ( _Objects_Is_auto_extend( information ) ) {
       object_blocks = _Workspace_Allocate( table_size );
       if ( !object_blocks ) {
         _Workspace_Free( new_object_block );
diff --git a/cpukit/score/src/objectfree.c b/cpukit/score/src/objectfree.c
index cf31a5b24e..38ae17d739 100644
--- a/cpukit/score/src/objectfree.c
+++ b/cpukit/score/src/objectfree.c
@@ -31,7 +31,7 @@ void _Objects_Free(
 
   _Chain_Append_unprotected( &information->Inactive, &the_object->Node );
 
-  if ( information->auto_extend ) {
+  if ( _Objects_Is_auto_extend( information ) ) {
     Objects_Maximum objects_per_block;
     Objects_Maximum block;
     Objects_Maximum inactive;
diff --git a/cpukit/score/src/objectinitializeinformation.c b/cpukit/score/src/objectinitializeinformation.c
index d51d5cfca6..57e588ad4a 100644
--- a/cpukit/score/src/objectinitializeinformation.c
+++ b/cpukit/score/src/objectinitializeinformation.c
@@ -39,11 +39,12 @@ void _Objects_Do_initialize_information(
 {
   Objects_Maximum maximum_per_allocation;
 
+  maximum_per_allocation = _Objects_Maximum_per_allocation( maximum );
   information->maximum_id = _Objects_Build_id(
     the_api,
     the_class,
     _Objects_Local_node,
-    0
+    maximum_per_allocation
   );
   information->object_size = object_size;
 
@@ -55,20 +56,20 @@ void _Objects_Do_initialize_information(
   /*
    *  Are we operating in limited or unlimited (e.g. auto-extend) mode.
    */
-  information->auto_extend = _Objects_Is_unlimited( maximum );
-  maximum_per_allocation = _Objects_Maximum_per_allocation( maximum );
+  if ( _Objects_Is_unlimited( maximum ) ) {
+    /*
+     *  Unlimited and maximum of zero is illogical.
+     */
+    if ( maximum_per_allocation == 0) {
+      _Internal_error( INTERNAL_ERROR_UNLIMITED_AND_MAXIMUM_IS_0 );
+    }
 
-  /*
-   *  Unlimited and maximum of zero is illogical.
-   */
-  if ( information->auto_extend && maximum_per_allocation == 0) {
-    _Internal_error( INTERNAL_ERROR_UNLIMITED_AND_MAXIMUM_IS_0 );
+    /*
+     *  The allocation unit is the maximum value
+     */
+    information->objects_per_block = maximum_per_allocation;
   }
 
-  /*
-   *  The allocation unit is the maximum value
-   */
-  information->objects_per_block = maximum_per_allocation;
 
   /*
    *  Calculate the maximum name length
diff --git a/testsuites/samples/unlimited/test1.c b/testsuites/samples/unlimited/test1.c
index f02857ce59..a529c71be3 100644
--- a/testsuites/samples/unlimited/test1.c
+++ b/testsuites/samples/unlimited/test1.c
@@ -30,7 +30,7 @@
 
 void test1()
 {
-  bool                 auto_extend;
+  Objects_Maximum      objects_per_block;
   rtems_status_code    result;
   uint32_t             task_count = 0;
   Objects_Information *the_information;
@@ -49,8 +49,8 @@ void test1()
 
   the_information =
     _Objects_Information_table[OBJECTS_CLASSIC_API][OBJECTS_RTEMS_TASKS];
-  auto_extend = the_information->auto_extend;
-  the_information->auto_extend = false;
+  objects_per_block = the_information->objects_per_block;
+  the_information->objects_per_block = 0;
 
   while (task_count < MAX_TASKS)
   {
@@ -101,7 +101,7 @@ void test1()
 
   destroy_all_tasks("TEST1");
 
-  the_information->auto_extend = auto_extend;
+  the_information->objects_per_block = objects_per_block;
 
   printf( " TEST1 : completed\n" );
 }
-- 
2.16.4




More information about the devel mailing list