X-Git-Url: https://git.liburcu.org/?p=urcu.git;a=blobdiff_plain;f=tests%2Ftest_urcu_lfq.c;h=82a90b0cdecc23f05c3572cf6b6819f00ac72531;hp=15023f6fcb0011f1e8db81dcf925a06fed32dc96;hb=7618919ae496bda84a2efa4f2ad0abe569892a9e;hpb=d9b52143813e104eeee1e3d90061042230b7b5bf diff --git a/tests/test_urcu_lfq.c b/tests/test_urcu_lfq.c index 15023f6..82a90b0 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,7 +65,7 @@ static inline pid_t gettid(void) #define _LGPL_SOURCE #endif #include -#include +#include #include static volatile int test_go, test_stop; @@ -177,9 +180,7 @@ 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)) @@ -202,20 +203,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; @@ -241,12 +228,9 @@ void *thr_dequeuer(void *_count) for (;;) { 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, ref_release_node); + defer_rcu(free, node); nr_successful_dequeues++; } @@ -259,7 +243,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, @@ -269,22 +252,14 @@ 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; do { - rcu_read_lock(); 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); @@ -381,7 +356,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); next_aff = 0; @@ -426,6 +401,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);