From b0f74e4734295f71a2c311817c0082223f2564d8 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Sun, 19 Aug 2012 09:28:53 -0400 Subject: [PATCH] rcuja: create shadow node for root Signed-off-by: Mathieu Desnoyers --- rcuja/rcuja-internal.h | 1 + rcuja/rcuja.c | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/rcuja/rcuja-internal.h b/rcuja/rcuja-internal.h index 28908e0..0277808 100644 --- a/rcuja/rcuja-internal.h +++ b/rcuja/rcuja-internal.h @@ -43,6 +43,7 @@ struct cds_ja_shadow_node { pthread_mutex_t *lock; unsigned int nr_child; /* number of children in node */ struct rcu_head head; /* for deferred node and shadow node reclaim */ + int is_root; /* is it a root node ? */ }; struct cds_ja { diff --git a/rcuja/rcuja.c b/rcuja/rcuja.c index 1c1d6e4..945b299 100644 --- a/rcuja/rcuja.c +++ b/rcuja/rcuja.c @@ -876,7 +876,8 @@ int cds_ja_add(struct cds_ja *ja, uint64_t key, retry: iter_key = key; parent2_node_flag = NULL; - parent_node_flag = NULL; + parent_node_flag = + (struct cds_ja_inode_flag *) &ja->root; /* Use root ptr address as key for mutex */ node_flag_ptr = &ja->root; node_flag = rcu_dereference(*node_flag_ptr); @@ -921,6 +922,7 @@ struct cds_ja *_cds_ja_new(unsigned int key_bits, const struct rcu_flavor_struct *flavor) { struct cds_ja *ja; + int ret; ja = calloc(sizeof(*ja), 1); if (!ja) @@ -950,8 +952,21 @@ struct cds_ja *_cds_ja_new(unsigned int key_bits, ja->ht = rcuja_create_ht(flavor); if (!ja->ht) goto ht_error; + + /* + * Note: we should not free this node until judy array destroy. + */ + ret = rcuja_shadow_set(ja->ht, + ja_node_ptr((struct cds_ja_inode_flag *) &ja->root), + NULL); + if (ret) + goto ht_node_error; + return ja; +ht_node_error: + ret = rcuja_delete_ht(ja->ht); + assert(!ret); ht_error: check_error: free(ja); -- 2.34.1