#include <urcu-rbtree.h>
#include <urcu-pointer.h>
+#ifdef DEBUG
+#define dbg_printf(args...) printf(args)
+#else
+#define dbg_printf(args...)
+#endif
+
/*
* TODO
* Deal with memory allocation errors.
{
struct rcu_rbtree_node *xc, *y, *yc, *b, *bc;
+ dbg_printf("left rotate %p\n", x->key);
+
y = x->right;
if (x != &rcu_rbtree_nil) {
*bc = *b;
assert(b->pos == IS_LEFT);
bc->pos = IS_RIGHT;
- }
+ } else
+ bc = &rcu_rbtree_nil;
/* Modify children and parents in the node copies */
if (x != &rcu_rbtree_nil) {
{
struct rcu_rbtree_node *x, *xc, *yc, *b, *bc;;
+ dbg_printf("right rotate %p\n", y->key);
+
x = y->left;
if (x != &rcu_rbtree_nil) {
*bc = *b;
assert(b->pos == IS_RIGHT);
bc->pos = IS_LEFT;
- }
+ } else
+ bc = &rcu_rbtree_nil;
/* Modify children and parents in the node copies */
if (x != &rcu_rbtree_nil) {
return yc;
}
-#if 0 //orig
-static void right_rotate(struct rcu_rbtree_node **root,
- struct rcu_rbtree_node *x,
- rcu_rbtree_alloc rballoc)
-{
- struct rcu_rbtree_node *y;
-
- y = x->left;
- x->left = y->right;
- if (y->right != &rcu_rbtree_nil)
- y->right->p = x;
- y->p = x->p;
- if (x->p == &rcu_rbtree_nil)
- *root = y;
- else if (x == x->p->right)
- x->p->right = y;
- else
- x->p->left = y;
- y->right = x;
- x->p = y;
-}
-#endif //0
-
static void rcu_rbtree_insert_fixup(struct rcu_rbtree_node **root,
struct rcu_rbtree_node *z,
rcu_rbtree_alloc rballoc,
{
struct rcu_rbtree_node *y;
+ dbg_printf("insert fixup %p\n", z->key);
+
while (z->p->color == COLOR_RED) {
if (z->p == z->p->p->left) {
y = z->p->p->right;
{
struct rcu_rbtree_node *x, *y;
+ dbg_printf("insert %p\n", z->key);
+
y = &rcu_rbtree_nil;
x = *root;
{
struct rcu_rbtree_node *vc;
+ dbg_printf("transplant %p\n", v->key);
+
if (v != &rcu_rbtree_nil) {
vc = rballoc();
*vc = *v;
rcu_rbtree_alloc rballoc,
rcu_rbtree_free rbfree)
{
+ dbg_printf("remove fixup %p\n", x->key);
+
while (x != *root && x->color == COLOR_BLACK) {
if (x == x->p->left) {
struct rcu_rbtree_node *w, *t;
{
struct rcu_rbtree_node *x, *xc, *yc;
+ dbg_printf("remove nonil %p\n", z->key);
+
x = y->right;
if (x != &rcu_rbtree_nil) {
struct rcu_rbtree_node *x, *y;
unsigned int y_original_color;
+ dbg_printf("remove %p\n", z->key);
+
y = z;
y_original_color = y->color;