X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=tests%2Ftest_urcu_lfq.c;h=cb50586ec3176ea6b4e3b100c8ba156d97295c38;hb=65fcc7e9957a1658327acd121c3d8c3b36f4a94e;hp=de7c8a39a209d30e54fd652c69e4f6fc72db0819;hpb=16aa9ee87cf4364921c36025359be01390338d87;p=urcu.git diff --git a/tests/test_urcu_lfq.c b/tests/test_urcu_lfq.c index de7c8a3..cb50586 100644 --- a/tests/test_urcu_lfq.c +++ b/tests/test_urcu_lfq.c @@ -34,12 +34,15 @@ #include #include #include -#include #include #include #include +#ifdef __linux__ +#include +#endif + /* hardcoded number of CPUs */ #define NR_CPUS 16384 @@ -62,8 +65,7 @@ static inline pid_t gettid(void) #define _LGPL_SOURCE #endif #include -#include -#include +#include static volatile int test_go, test_stop; @@ -177,7 +179,9 @@ void *thr_enqueuer(void *_count) if (!node) goto fail; cds_lfq_node_init_rcu(node); + rcu_read_lock(); cds_lfq_enqueue_rcu(&q, node); + rcu_read_unlock(); nr_successful_enqueues++; if (unlikely(wdelay)) @@ -200,24 +204,30 @@ fail: } -static void rcu_release_node(struct urcu_ref *ref) +static void rcu_free_node(struct rcu_head *head) { - struct cds_lfq_node_rcu *node = caa_container_of(ref, struct cds_lfq_node_rcu, ref); - defer_rcu(free, node); - //synchronize_rcu(); - //free(node); + 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; + int ret; printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n", "dequeuer", pthread_self(), (unsigned long)gettid()); set_affinity(); - rcu_defer_register_thread(); rcu_register_thread(); while (!test_go) @@ -226,11 +236,14 @@ void *thr_dequeuer(void *_count) cmm_smp_mb(); for (;;) { - struct cds_lfq_node_rcu *node = cds_lfq_dequeue_rcu(&q, - rcu_release_node); + struct cds_lfq_node_rcu *node; + + rcu_read_lock(); + node = cds_lfq_dequeue_rcu(&q); + rcu_read_unlock(); if (node) { - urcu_ref_put(&node->ref, rcu_release_node); + urcu_ref_put(&node->ref, ref_release_node); nr_successful_dequeues++; } @@ -242,8 +255,6 @@ 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,7 +275,9 @@ void test_end(struct cds_lfq_queue_rcu *q, unsigned long long *nr_dequeues) struct cds_lfq_node_rcu *node; do { - node = cds_lfq_dequeue_rcu(q, release_node); + rcu_read_lock(); + node = cds_lfq_dequeue_rcu(q); + rcu_read_unlock(); if (node) { urcu_ref_put(&node->ref, release_node); (*nr_dequeues)++; @@ -363,7 +376,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); + cds_lfq_init_rcu(&q, ref_release_node); next_aff = 0;