summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2016-08-24 15:25:33 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2016-09-06 10:52:19 +0200
commitda15db787bffe90e8ea8baac6a0cf6153922d088 (patch)
tree09c1a0393d630a9bd1f84e2d982d5c7aaa7e9277
parent83b022907173c9e1bd69874fadb5ed443400c2fa (diff)
downloadrtems-da15db787bffe90e8ea8baac6a0cf6153922d088.tar.bz2
score: Improve red-black tree debug support
Ensure that we extract a node only from the right tree.
-rw-r--r--cpukit/libfs/src/jffs2/include/linux/rbtree.h3
-rw-r--r--cpukit/score/include/rtems/score/rbtree.h10
-rw-r--r--cpukit/score/src/rbtreeextract.c5
-rw-r--r--cpukit/score/src/rbtreeinsert.c4
4 files changed, 19 insertions, 3 deletions
diff --git a/cpukit/libfs/src/jffs2/include/linux/rbtree.h b/cpukit/libfs/src/jffs2/include/linux/rbtree.h
index 2268434939..f958e6daae 100644
--- a/cpukit/libfs/src/jffs2/include/linux/rbtree.h
+++ b/cpukit/libfs/src/jffs2/include/linux/rbtree.h
@@ -22,6 +22,9 @@ struct rb_node {
struct rb_node *rb_right;
struct rb_node *rb_parent;
int rb_color;
+#if defined(RTEMS_DEBUG)
+ const RBTree_Control *rb_tree;
+#endif
};
RTEMS_STATIC_ASSERT(
diff --git a/cpukit/score/include/rtems/score/rbtree.h b/cpukit/score/include/rtems/score/rbtree.h
index 818eee4290..dd420b36a4 100644
--- a/cpukit/score/include/rtems/score/rbtree.h
+++ b/cpukit/score/include/rtems/score/rbtree.h
@@ -39,6 +39,8 @@ extern "C" {
*/
/**@{*/
+struct RBTree_Control;
+
/**
* @brief Red-black tree node.
*
@@ -47,6 +49,9 @@ extern "C" {
*/
typedef struct RBTree_Node {
RB_ENTRY(RBTree_Node) Node;
+#if defined(RTEMS_DEBUG)
+ const struct RBTree_Control *tree;
+#endif
} RBTree_Node;
/**
@@ -124,6 +129,7 @@ RTEMS_INLINE_ROUTINE void _RBTree_Initialize_node( RBTree_Node *the_node )
{
#if defined(RTEMS_DEBUG)
_RBTree_Set_off_tree( the_node );
+ the_node->tree = NULL;
#endif
}
@@ -400,6 +406,10 @@ RTEMS_INLINE_ROUTINE void _RBTree_Initialize_one(
)
{
_Assert( _RBTree_Is_node_off_tree( the_node ) );
+#if defined(RTEMS_DEBUG)
+ _Assert( the_node->tree == NULL );
+ the_node->tree = the_rbtree;
+#endif
RB_ROOT( the_rbtree ) = the_node;
RB_PARENT( the_node, Node ) = NULL;
RB_LEFT( the_node, Node ) = NULL;
diff --git a/cpukit/score/src/rbtreeextract.c b/cpukit/score/src/rbtreeextract.c
index 3905f64900..8a87b2d56c 100644
--- a/cpukit/score/src/rbtreeextract.c
+++ b/cpukit/score/src/rbtreeextract.c
@@ -21,8 +21,7 @@ void _RBTree_Extract(
RBTree_Node *the_node
)
{
+ _Assert( the_node->tree == the_rbtree );
RB_REMOVE( RBTree_Control, the_rbtree, the_node );
-#if defined(RTEMS_DEBUG)
- _RBTree_Set_off_tree( the_node );
-#endif
+ _RBTree_Initialize_node( the_node );
}
diff --git a/cpukit/score/src/rbtreeinsert.c b/cpukit/score/src/rbtreeinsert.c
index c8bbef9aad..99dc2a233f 100644
--- a/cpukit/score/src/rbtreeinsert.c
+++ b/cpukit/score/src/rbtreeinsert.c
@@ -19,5 +19,9 @@ void _RBTree_Insert_color(
RBTree_Node *the_node
)
{
+#if defined(RTEMS_DEBUG)
+ _Assert( the_node->tree == NULL );
+ the_node->tree = the_rbtree;
+#endif
RBTree_Control_RB_INSERT_COLOR( the_rbtree, the_node );
}