X-Git-Url: https://git.lttng.org/?p=urcu.git;a=blobdiff_plain;f=tests%2Ftest_urcu_lfq.c;h=b61a7d4815788af2bcd9e197dc319a8eb053791a;hp=cb50586ec3176ea6b4e3b100c8ba156d97295c38;hb=e17d9985aeb7eab28f3ab1ba5a3076b49d504958;hpb=bd0662dbc16afea5287d66c668d7bc2600151b47 diff --git a/tests/test_urcu_lfq.c b/tests/test_urcu_lfq.c index cb50586..b61a7d4 100644 --- a/tests/test_urcu_lfq.c +++ b/tests/test_urcu_lfq.c @@ -66,6 +66,7 @@ static inline pid_t gettid(void) #endif #include #include +#include static volatile int test_go, test_stop; @@ -204,20 +205,6 @@ fail: } -static void rcu_free_node(struct rcu_head *head) -{ - struct cds_lfq_node_rcu *node = - caa_container_of(head, struct cds_lfq_node_rcu, rcu_head); - free(node); -} - -static void ref_release_node(struct urcu_ref *ref) -{ - struct cds_lfq_node_rcu *node = - caa_container_of(ref, struct cds_lfq_node_rcu, ref); - call_rcu(&node->rcu_head, rcu_free_node); -} - void *thr_dequeuer(void *_count) { unsigned long long *count = _count; @@ -228,6 +215,11 @@ void *thr_dequeuer(void *_count) set_affinity(); + ret = rcu_defer_register_thread(); + if (ret) { + printf("Error in rcu_defer_register_thread\n"); + exit(-1); + } rcu_register_thread(); while (!test_go) @@ -243,7 +235,7 @@ void *thr_dequeuer(void *_count) rcu_read_unlock(); if (node) { - urcu_ref_put(&node->ref, ref_release_node); + defer_rcu(free, node); nr_successful_dequeues++; } @@ -255,6 +247,7 @@ void *thr_dequeuer(void *_count) } rcu_unregister_thread(); + rcu_defer_unregister_thread(); printf_verbose("dequeuer thread_end, thread id : %lx, tid %lu, " "dequeues %llu, successful_dequeues %llu\n", pthread_self(), (unsigned long)gettid(), nr_dequeues, @@ -264,12 +257,6 @@ void *thr_dequeuer(void *_count) return ((void*)2); } -static void release_node(struct urcu_ref *ref) -{ - struct cds_lfq_node_rcu *node = caa_container_of(ref, struct cds_lfq_node_rcu, ref); - free(node); -} - void test_end(struct cds_lfq_queue_rcu *q, unsigned long long *nr_dequeues) { struct cds_lfq_node_rcu *node; @@ -279,7 +266,7 @@ void test_end(struct cds_lfq_queue_rcu *q, unsigned long long *nr_dequeues) node = cds_lfq_dequeue_rcu(q); rcu_read_unlock(); if (node) { - urcu_ref_put(&node->ref, release_node); + free(node); /* no more concurrent access */ (*nr_dequeues)++; } } while (node); @@ -376,7 +363,7 @@ int main(int argc, char **argv) tid_dequeuer = malloc(sizeof(*tid_dequeuer) * nr_dequeuers); count_enqueuer = malloc(2 * sizeof(*count_enqueuer) * nr_enqueuers); count_dequeuer = malloc(2 * sizeof(*count_dequeuer) * nr_dequeuers); - cds_lfq_init_rcu(&q, ref_release_node); + cds_lfq_init_rcu(&q, call_rcu); next_aff = 0; @@ -421,6 +408,8 @@ int main(int argc, char **argv) } test_end(&q, &end_dequeues); + err = cds_lfq_destroy_rcu(&q); + assert(!err); printf_verbose("total number of enqueues : %llu, dequeues %llu\n", tot_enqueues, tot_dequeues);