[rtems commit] score: Add and use _RBTree_Insert_inline()

Sebastian Huber sebh at rtems.org
Fri Apr 1 07:11:17 UTC 2016


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Thu Mar 31 13:31:24 2016 +0200

score: Add and use _RBTree_Insert_inline()

---

 cpukit/posix/include/rtems/posix/keyimpl.h | 26 +++----------------
 cpukit/score/include/rtems/score/rbtree.h  | 40 ++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 22 deletions(-)

diff --git a/cpukit/posix/include/rtems/posix/keyimpl.h b/cpukit/posix/include/rtems/posix/keyimpl.h
index 7715fdf..7095a16 100644
--- a/cpukit/posix/include/rtems/posix/keyimpl.h
+++ b/cpukit/posix/include/rtems/posix/keyimpl.h
@@ -158,29 +158,11 @@ RTEMS_INLINE_ROUTINE void _POSIX_Keys_Key_value_insert(
   Thread_Control            *the_thread
 )
 {
-  RBTree_Node **link;
-  RBTree_Node  *parent;
-
-  link = _RBTree_Root_reference( &the_thread->Keys.Key_value_pairs );
-  parent = NULL;
-
-  while ( *link != NULL ) {
-    POSIX_Keys_Key_value_pair *parent_key_value_pair;
-
-    parent = *link;
-    parent_key_value_pair = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( parent );
-
-    if ( key < parent_key_value_pair->key ) {
-      link = _RBTree_Left_reference( parent );
-    } else {
-      link = _RBTree_Right_reference( parent );
-    }
-  }
-
-  _RBTree_Add_child( &key_value_pair->Lookup_node, parent, link );
-  _RBTree_Insert_color(
+  _RBTree_Insert_inline(
     &the_thread->Keys.Key_value_pairs,
-    &key_value_pair->Lookup_node
+    &key_value_pair->Lookup_node,
+    &key,
+    _POSIX_Keys_Key_value_less
   );
 }
 
diff --git a/cpukit/score/include/rtems/score/rbtree.h b/cpukit/score/include/rtems/score/rbtree.h
index 111b231..2057612 100644
--- a/cpukit/score/include/rtems/score/rbtree.h
+++ b/cpukit/score/include/rtems/score/rbtree.h
@@ -484,6 +484,46 @@ void _RBTree_Replace_node(
 );
 
 /**
+ * @brief Inserts the node into the red-black tree.
+ *
+ * @param the_rbtree The red-black tree control.
+ * @param the_node The node to insert.
+ * @param key The key of the node to insert.  This key must be equal to the key
+ *   stored in the node to insert.  The separate key parameter is provided for
+ *   two reasons.  Firstly, it allows to share the less operator with
+ *   _RBTree_Find_inline().  Secondly, the compiler may generate better code if
+ *   the key is stored in a local variable.
+ * @param less Must return true if the specified key is less than the key of
+ *   the node, otherwise false.
+ */
+RTEMS_INLINE_ROUTINE void _RBTree_Insert_inline(
+  RBTree_Control *the_rbtree,
+  RBTree_Node    *the_node,
+  const void     *key,
+  bool         ( *less )( const void *, const RBTree_Node * )
+)
+{
+  RBTree_Node **link;
+  RBTree_Node  *parent;
+
+  link = _RBTree_Root_reference( the_rbtree );
+  parent = NULL;
+
+  while ( *link != NULL ) {
+    parent = *link;
+
+    if ( ( *less )( key, parent ) ) {
+      link = _RBTree_Left_reference( parent );
+    } else {
+      link = _RBTree_Right_reference( parent );
+    }
+  }
+
+  _RBTree_Add_child( the_node, parent, link );
+  _RBTree_Insert_color( the_rbtree, the_node );
+}
+
+/**
  * @brief Finds a node in the red-black tree with the specified key.
  *
  * @param the_rbtree The red-black tree control.



More information about the vc mailing list