[rtems commit] rbtree: New function _RBTree_Iterate_unprotected()

Sebastian Huber sebh at rtems.org
Wed Apr 11 09:23:14 UTC 2012


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Tue Apr 10 10:54:22 2012 +0200

rbtree: New function _RBTree_Iterate_unprotected()

---

 cpukit/score/Makefile.am                  |    3 +-
 cpukit/score/include/rtems/score/rbtree.h |   33 +++++++++++++++++++++
 cpukit/score/src/rbtreeiterate.c          |   45 +++++++++++++++++++++++++++++
 3 files changed, 80 insertions(+), 1 deletions(-)

diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am
index 1c896e3..2f12905 100644
--- a/cpukit/score/Makefile.am
+++ b/cpukit/score/Makefile.am
@@ -265,7 +265,8 @@ libscore_a_SOURCES += src/pheapallocate.c \
 ## RBTREE_C_FILES
 libscore_a_SOURCES += src/rbtree.c \
     src/rbtreeextract.c src/rbtreefind.c src/rbtreefindheader.c \
-    src/rbtreeget.c src/rbtreeinsert.c src/rbtreepeek.c src/rbtreenext.c
+    src/rbtreeget.c src/rbtreeinsert.c src/rbtreepeek.c src/rbtreenext.c \
+    src/rbtreeiterate.c
 
 ## THREAD_C_FILES
 libscore_a_SOURCES += src/thread.c src/threadchangepriority.c \
diff --git a/cpukit/score/include/rtems/score/rbtree.h b/cpukit/score/include/rtems/score/rbtree.h
index b2e5776..2e9bb83 100644
--- a/cpukit/score/include/rtems/score/rbtree.h
+++ b/cpukit/score/include/rtems/score/rbtree.h
@@ -348,6 +348,39 @@ RBTree_Node *_RBTree_Next(
   RBTree_Direction dir
 );
 
+/**
+ * @brief Red-black tree visitor.
+ *
+ * @param[in] node The node.
+ * @param[in] dir The direction.
+ * @param[in] visitor_arg The visitor argument.
+ *
+ * @retval true Stop the iteration.
+ * @retval false Continue the iteration.
+ *
+ * @see _RBTree_Iterate_unprotected().
+ */
+typedef bool (*RBTree_Visitor)(
+  const RBTree_Node *node,
+  RBTree_Direction dir,
+  void *visitor_arg
+);
+
+/**
+ * @brief Red-black tree iteration.
+ *
+ * @param[in] rbtree The red-black tree.
+ * @param[in] dir The direction.
+ * @param[in] visitor The visitor.
+ * @param[in] visitor_arg The visitor argument.
+ */
+void _RBTree_Iterate_unprotected(
+  const RBTree_Control *rbtree,
+  RBTree_Direction dir,
+  RBTree_Visitor visitor,
+  void *visitor_arg
+);
+
 #ifndef __RTEMS_APPLICATION__
 #include <rtems/score/rbtree.inl>
 #endif
diff --git a/cpukit/score/src/rbtreeiterate.c b/cpukit/score/src/rbtreeiterate.c
new file mode 100644
index 0000000..33f7e7d
--- /dev/null
+++ b/cpukit/score/src/rbtreeiterate.c
@@ -0,0 +1,45 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreRBTree
+ *
+ * @brief _RBTree_Iterate_unprotected() implementation.
+ */
+
+/*
+ * Copyright (c) 2012 embedded brains GmbH.  All rights reserved.
+ *
+ *  embedded brains GmbH
+ *  Obere Lagerstr. 30
+ *  82178 Puchheim
+ *  Germany
+ *  <rtems at embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#if HAVE_CONFIG_H
+  #include "config.h"
+#endif
+
+#include <rtems/score/rbtree.h>
+
+void _RBTree_Iterate_unprotected(
+  const RBTree_Control *rbtree,
+  RBTree_Direction dir,
+  RBTree_Visitor visitor,
+  void *visitor_arg
+)
+{
+  RBTree_Direction opp_dir = _RBTree_Opposite_direction( dir );
+  const RBTree_Node *current = _RBTree_First( rbtree, opp_dir );
+  bool stop = false;
+
+  while ( !stop && current != NULL ) {
+    stop = (*visitor)( current, dir, visitor_arg );
+
+    current = _RBTree_Next_unprotected( rbtree, current, dir );
+  }
+}




More information about the vc mailing list