[PATCH 19/21] score: Add _Freechain_Extend()

Sebastian Huber sebastian.huber at embedded-brains.de
Mon Dec 16 14:28:24 UTC 2019


Update #3835.
---
 cpukit/include/rtems/score/freechain.h | 18 ++++++++++++++++++
 cpukit/score/src/freechain.c           | 33 +++++++++++++++++++++++++--------
 2 files changed, 43 insertions(+), 8 deletions(-)

diff --git a/cpukit/include/rtems/score/freechain.h b/cpukit/include/rtems/score/freechain.h
index e656f64f8e..eaee077366 100644
--- a/cpukit/include/rtems/score/freechain.h
+++ b/cpukit/include/rtems/score/freechain.h
@@ -103,6 +103,24 @@ RTEMS_INLINE_ROUTINE void *_Freechain_Pop( Freechain_Control *freechain )
   return _Chain_Get_first_unprotected( &freechain->Free );
 }
 
+/**
+ * @brief Extend the freechain with new nodes.
+ *
+ * @param freechain The freechain control.
+ * @param allocator The allocator function.
+ * @param number_nodes_to_extend The number of nodes to extend.
+ * @param node_size The node size.
+ *
+ * @retval NULL The extend operation failed.
+ * @retval nodes Pointer to the new nodes.
+ */
+void *_Freechain_Extend(
+  Freechain_Control   *freechain,
+  Freechain_Allocator  allocator,
+  size_t               number_nodes_to_extend,
+  size_t               node_size
+);
+
 /**
  * @brief Gets a node from the freechain.
  *
diff --git a/cpukit/score/src/freechain.c b/cpukit/score/src/freechain.c
index f7da12216d..f15ce1ea4f 100644
--- a/cpukit/score/src/freechain.c
+++ b/cpukit/score/src/freechain.c
@@ -21,6 +21,28 @@
 #include <rtems/score/freechain.h>
 #include <rtems/score/assert.h>
 
+void *_Freechain_Extend(
+  Freechain_Control   *freechain,
+  Freechain_Allocator  allocator,
+  size_t               number_nodes_to_extend,
+  size_t               node_size
+)
+{
+  void *starting_address;
+
+  starting_address = ( *allocator )( number_nodes_to_extend * node_size );
+  number_nodes_to_extend *= ( starting_address != NULL );
+
+  _Chain_Initialize(
+    &freechain->Free,
+    starting_address,
+    number_nodes_to_extend,
+    node_size
+  );
+
+  return starting_address;
+}
+
 void *_Freechain_Get(
   Freechain_Control   *freechain,
   Freechain_Allocator  allocator,
@@ -31,14 +53,9 @@ void *_Freechain_Get(
   _Assert( node_size >= sizeof( Chain_Node ) );
 
   if ( _Chain_Is_empty( &freechain->Free ) && number_nodes_to_extend > 0 ) {
-    void *starting_address;
-
-    starting_address = ( *allocator )( number_nodes_to_extend * node_size );
-    number_nodes_to_extend *= ( starting_address != NULL );
-
-    _Chain_Initialize(
-      &freechain->Free,
-      starting_address,
+    _Freechain_Extend(
+      freechain,
+      allocator,
       number_nodes_to_extend,
       node_size
     );
-- 
2.16.4



More information about the devel mailing list