[PATCH 04/29] linux: Add rbtree_postorder_for_each_entry_safe()

Sebastian Huber sebastian.huber at embedded-brains.de
Thu Jul 5 07:49:24 UTC 2018


Update #3465.

16	0	cpukit/include/linux/rbtree.h
22	0	testsuites/sptests/sprbtree01/init.c

diff --git a/cpukit/include/linux/rbtree.h b/cpukit/include/linux/rbtree.h
index e1da2c7b9a..53c777e8c1 100644
--- a/cpukit/include/linux/rbtree.h
+++ b/cpukit/include/linux/rbtree.h
@@ -122,4 +122,20 @@ static inline struct rb_node *rb_parent( struct rb_node *node )
   return _RBTree_Parent( node );
 }
 
+#define rbtree_postorder_for_each_entry_safe( node, next, root, field ) \
+  for ( \
+    node = _RBTree_Postorder_first( \
+      (RBTree_Control *) root, \
+      (size_t) ( (char *) &node->field - (char *) node ) \
+    ); \
+    node != NULL && ( \
+      next = _RBTree_Postorder_next( \
+        &node->field, \
+        (size_t) ( (char *) &node->field - (char *) node ) \
+      ), \
+      node != NULL \
+    ); \
+    node = next \
+  )
+
 #endif /* _LINUX_RBTREE_H */
diff --git a/testsuites/sptests/sprbtree01/init.c b/testsuites/sptests/sprbtree01/init.c
index 7a969cfa4a..fd45a3654a 100644
--- a/testsuites/sptests/sprbtree01/init.c
+++ b/testsuites/sptests/sprbtree01/init.c
@@ -14,6 +14,8 @@
 #include <rtems/rbtree.h>
 #include <rtems/score/rbtreeimpl.h>
 
+#include <linux/rbtree.h>
+
 const char rtems_test_name[] = "SPRBTREE 1";
 
 /* forward declarations to avoid warnings */
@@ -1911,6 +1913,7 @@ static void postorder_tree_check(
 )
 {
   test_node *node;
+  test_node *next;
   size_t i;
 
   node = _RBTree_Postorder_first( tree, offsetof( test_node, Node ) );
@@ -1921,6 +1924,25 @@ static void postorder_tree_check(
   }
 
   rtems_test_assert( node == NULL );
+
+  i = 0;
+  next = NULL;
+
+  rbtree_postorder_for_each_entry_safe( node, next, tree, Node ) {
+    rtems_test_assert( node == &node_array[ i ] );
+
+    if ( i < pt->node_count - 1 ) {
+      rtems_test_assert( next == &node_array[ i + 1 ] );
+    } else {
+      rtems_test_assert( next == NULL );
+    }
+
+    ++i;
+  }
+
+  rtems_test_assert( i == pt->node_count );
+  rtems_test_assert( node == NULL );
+  rtems_test_assert( next == NULL );
 }
 
 static void test_rbtree_postorder( void )
-- 
2.13.7




More information about the devel mailing list