From: Mathieu Desnoyers Date: Wed, 5 Jun 2013 15:00:28 +0000 (-0400) Subject: rcuja: API change: move rcu_head to user code X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=21ac4c56cd0edffc0590b649b6ed1e7b61269b20;p=urcu.git rcuja: API change: move rcu_head to user code Signed-off-by: Mathieu Desnoyers --- diff --git a/rcuja/rcuja-internal.h b/rcuja/rcuja-internal.h index cf4ef96..9b1daca 100644 --- a/rcuja/rcuja-internal.h +++ b/rcuja/rcuja-internal.h @@ -149,7 +149,7 @@ struct cds_ja_inode *ja_node_ptr(struct cds_ja_inode_flag *node); __attribute__((visibility("protected"))) void rcuja_free_all_children(struct cds_ja_shadow_node *shadow_node, struct cds_ja_inode_flag *node_flag, - void (*free_node_cb)(struct rcu_head *head)); + void (*rcu_free_node)(struct cds_ja_node *node)); __attribute__((visibility("protected"))) struct cds_ja_shadow_node *rcuja_shadow_lookup_lock(struct cds_lfht *ht, @@ -179,7 +179,7 @@ int rcuja_shadow_clear(struct cds_lfht *ht, __attribute__((visibility("protected"))) void rcuja_shadow_prune(struct cds_lfht *ht, unsigned int flags, - void (*free_node_cb)(struct rcu_head *head)); + void (*rcu_free_node)(struct cds_ja_node *node)); __attribute__((visibility("protected"))) struct cds_lfht *rcuja_create_ht(const struct rcu_flavor_struct *flavor); diff --git a/rcuja/rcuja-shadow-nodes.c b/rcuja/rcuja-shadow-nodes.c index 1c6124e..917c6a2 100644 --- a/rcuja/rcuja-shadow-nodes.c +++ b/rcuja/rcuja-shadow-nodes.c @@ -377,7 +377,7 @@ rcu_unlock: __attribute__((visibility("protected"))) void rcuja_shadow_prune(struct cds_lfht *ht, unsigned int flags, - void (*free_node_cb)(struct rcu_head *head)) + void (*rcu_free_node)(struct cds_ja_node *node)) { const struct rcu_flavor_struct *flavor; struct cds_ja_shadow_node *shadow_node; @@ -397,7 +397,7 @@ void rcuja_shadow_prune(struct cds_lfht *ht, if (shadow_node->level == shadow_node->ja->tree_depth - 1) { rcuja_free_all_children(shadow_node, shadow_node->node_flag, - free_node_cb); + rcu_free_node); } if (flags & RCUJA_SHADOW_CLEAR_FREE_LOCK) { flavor->update_call_rcu(&shadow_node->head, diff --git a/rcuja/rcuja.c b/rcuja/rcuja.c index 1103116..4d1f2b4 100644 --- a/rcuja/rcuja.c +++ b/rcuja/rcuja.c @@ -2529,14 +2529,12 @@ ja_error: __attribute__((visibility("protected"))) void rcuja_free_all_children(struct cds_ja_shadow_node *shadow_node, struct cds_ja_inode_flag *node_flag, - void (*free_node_cb)(struct rcu_head *head)) + void (*rcu_free_node)(struct cds_ja_node *node)) { - const struct rcu_flavor_struct *flavor; unsigned int type_index; struct cds_ja_inode *node; const struct cds_ja_type *type; - flavor = cds_lfht_rcu_flavor(shadow_node->ja->ht); node = ja_node_ptr(node_flag); assert(node != NULL); type_index = ja_node_type(node_flag); @@ -2561,7 +2559,7 @@ void rcuja_free_all_children(struct cds_ja_shadow_node *shadow_node, continue; head.next = (struct cds_hlist_node *) iter; cds_hlist_for_each_entry_safe(entry, pos, tmp, &head, list) { - flavor->update_call_rcu(&entry->head, free_node_cb); + rcu_free_node(entry); } } break; @@ -2589,7 +2587,7 @@ void rcuja_free_all_children(struct cds_ja_shadow_node *shadow_node, continue; head.next = (struct cds_hlist_node *) iter; cds_hlist_for_each_entry_safe(entry, pos, tmp, &head, list) { - flavor->update_call_rcu(&entry->head, free_node_cb); + rcu_free_node(entry); } } } @@ -2612,7 +2610,7 @@ void rcuja_free_all_children(struct cds_ja_shadow_node *shadow_node, continue; head.next = (struct cds_hlist_node *) iter; cds_hlist_for_each_entry_safe(entry, pos, tmp, &head, list) { - flavor->update_call_rcu(&entry->head, free_node_cb); + rcu_free_node(entry); } } break; @@ -2671,7 +2669,7 @@ int ja_final_checks(struct cds_ja *ja) * being destroyed (ensured by the caller). */ int cds_ja_destroy(struct cds_ja *ja, - void (*free_node_cb)(struct rcu_head *head)) + void (*rcu_free_node)(struct cds_ja_node *node)) { const struct rcu_flavor_struct *flavor; int ret; @@ -2679,7 +2677,7 @@ int cds_ja_destroy(struct cds_ja *ja, flavor = cds_lfht_rcu_flavor(ja->ht); rcuja_shadow_prune(ja->ht, RCUJA_SHADOW_CLEAR_FREE_NODE | RCUJA_SHADOW_CLEAR_FREE_LOCK, - free_node_cb); + rcu_free_node); flavor->thread_offline(); ret = rcuja_delete_ht(ja->ht); if (ret) diff --git a/tests/test_urcu_ja.c b/tests/test_urcu_ja.c index 63683b6..7230ec6 100644 --- a/tests/test_urcu_ja.c +++ b/tests/test_urcu_ja.c @@ -156,10 +156,24 @@ static void free_node_cb(struct rcu_head *head) { struct ja_test_node *node = - caa_container_of(head, struct ja_test_node, node.head); + caa_container_of(head, struct ja_test_node, head); free_node(node); } +static +void rcu_free_test_node(struct ja_test_node *test_node) +{ + call_rcu(&test_node->head, free_node_cb); +} + +static +void rcu_free_node(struct cds_ja_node *node) +{ + struct ja_test_node *test_node = to_test_node(node); + + rcu_free_test_node(test_node); +} + #if 0 static void test_delete_all_nodes(struct cds_lfht *ht) @@ -286,7 +300,7 @@ int test_8bit_key(void) fprintf(stderr, "Error (%d) removing node %" PRIu64 "\n", ret, key); assert(0); } - call_rcu(&node->node.head, free_node_cb); + rcu_free_test_node(node); head = cds_ja_lookup(test_ja, key); if (!cds_hlist_empty(&head)) { fprintf(stderr, "Error lookup %" PRIu64 ": %p (after delete) failed. Node is not expected.\n", key, head.next); @@ -357,7 +371,7 @@ int test_8bit_key(void) printf("OK\n"); - ret = cds_ja_destroy(test_ja, free_node_cb); + ret = cds_ja_destroy(test_ja, rcu_free_node); if (ret) { fprintf(stderr, "Error destroying judy array\n"); return -1; @@ -445,7 +459,7 @@ int test_16bit_key(void) fprintf(stderr, "Error (%d) removing node %" PRIu64 "\n", ret, key); assert(0); } - call_rcu(&node->node.head, free_node_cb); + rcu_free_test_node(node); head = cds_ja_lookup(test_ja, key); if (!cds_hlist_empty(&head)) { fprintf(stderr, "Error lookup %" PRIu64 ": %p (after delete) failed. Node is not expected.\n", key, head.next); @@ -516,7 +530,7 @@ int test_16bit_key(void) printf("OK\n"); - ret = cds_ja_destroy(test_ja, free_node_cb); + ret = cds_ja_destroy(test_ja, rcu_free_node); if (ret) { fprintf(stderr, "Error destroying judy array\n"); return -1; @@ -638,7 +652,7 @@ int test_sparse_key(unsigned int bits, int nr_dup) fprintf(stderr, "Error (%d) removing node %" PRIu64 "\n", ret, key); assert(0); } - call_rcu(&node->node.head, free_node_cb); + rcu_free_test_node(node); testhead = cds_ja_lookup(test_ja, key); if (count < nr_dup && cds_hlist_empty(&testhead)) { fprintf(stderr, "Error: no node found after deletion of some nodes of a key\n"); @@ -656,7 +670,7 @@ int test_sparse_key(unsigned int bits, int nr_dup) } printf("OK\n"); - ret = cds_ja_destroy(test_ja, free_node_cb); + ret = cds_ja_destroy(test_ja, rcu_free_node); if (ret) { fprintf(stderr, "Error destroying judy array\n"); return -1; @@ -858,7 +872,7 @@ void *test_ja_rw_thr_writer(void *_count) if (node) { ret = cds_ja_del(test_ja, key, &node->node); if (!ret) { - call_rcu(&node->node.head, free_node_cb); + rcu_free_test_node(node); URCU_TLS(nr_del)++; } else { URCU_TLS(nr_delnoent)++; @@ -1001,7 +1015,7 @@ int do_mt_test(void) } rcu_thread_online_qsbr(); - ret = cds_ja_destroy(test_ja, free_node_cb); + ret = cds_ja_destroy(test_ja, rcu_free_node); if (ret) { fprintf(stderr, "Error destroying judy array\n"); goto end; diff --git a/tests/test_urcu_ja.h b/tests/test_urcu_ja.h index 3174613..873b493 100644 --- a/tests/test_urcu_ja.h +++ b/tests/test_urcu_ja.h @@ -106,7 +106,8 @@ extern struct cds_ja *test_ja; struct ja_test_node { struct cds_ja_node node; - uint64_t key; /* for testing */ + uint64_t key; /* for testing */ + struct rcu_head head; /* delayed reclaim */ }; static inline struct ja_test_node * diff --git a/urcu/rcuja.h b/urcu/rcuja.h index e66ce7e..a6407b6 100644 --- a/urcu/rcuja.h +++ b/urcu/rcuja.h @@ -39,8 +39,6 @@ extern "C" { struct cds_ja_node { /* Linked list of nodes with same key */ struct cds_hlist_node list; - /* delayed reclaim */ - struct rcu_head head; }; struct cds_ja; @@ -80,7 +78,7 @@ struct cds_ja *cds_ja_new(unsigned int key_bits) } int cds_ja_destroy(struct cds_ja *ja, - void (*free_node_cb)(struct rcu_head *head)); + void (*rcu_free_node_cb)(struct cds_ja_node *node)); #ifdef __cplusplus }