[rtems commit] score: Add _Freechain_Extend()

Sebastian Huber sebh at rtems.org
Wed Feb 12 15:11:59 UTC 2020


Module:    rtems
Branch:    master
Commit:    8a43adbe47454689149bac27adc45439eab44965
Changeset: http://git.rtems.org/rtems/commit/?id=8a43adbe47454689149bac27adc45439eab44965

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Tue Dec 10 11:09:32 2019 +0100

score: Add _Freechain_Extend()

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 e656f64..eaee077 100644
--- a/cpukit/include/rtems/score/freechain.h
+++ b/cpukit/include/rtems/score/freechain.h
@@ -104,6 +104,24 @@ RTEMS_INLINE_ROUTINE void *_Freechain_Pop( Freechain_Control *freechain )
 }
 
 /**
+ * @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.
  *
  * @param[in, out] freechain The freechain control.
diff --git a/cpukit/score/src/freechain.c b/cpukit/score/src/freechain.c
index f7da122..f15ce1e 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
     );



More information about the vc mailing list