X-Git-Url: https://git.liburcu.org/?p=urcu.git;a=blobdiff_plain;f=tests%2Ftest_urcu_lfq.c;h=5292ebd4c4f35e673b7e52588cc526c326fcb6be;hp=82a90b0cdecc23f05c3572cf6b6819f00ac72531;hb=1f689e13ea7e519b1afc001e9c55a7b1b60b599f;hpb=7618919ae496bda84a2efa4f2ad0abe569892a9e diff --git a/tests/test_urcu_lfq.c b/tests/test_urcu_lfq.c index 82a90b0..5292ebd 100644 --- a/tests/test_urcu_lfq.c +++ b/tests/test_urcu_lfq.c @@ -157,6 +157,11 @@ static unsigned long long __thread nr_successful_enqueues; static unsigned int nr_enqueuers; static unsigned int nr_dequeuers; +struct test { + struct cds_lfq_node_rcu list; + struct rcu_head rcu; +}; + static struct cds_lfq_queue_rcu q; void *thr_enqueuer(void *_count) @@ -176,11 +181,13 @@ void *thr_enqueuer(void *_count) cmm_smp_mb(); for (;;) { - struct cds_lfq_node_rcu *node = malloc(sizeof(*node)); + struct test *node = malloc(sizeof(*node)); if (!node) goto fail; - cds_lfq_node_init_rcu(node); - cds_lfq_enqueue_rcu(&q, node); + cds_lfq_node_init_rcu(&node->list); + rcu_read_lock(); + cds_lfq_enqueue_rcu(&q, &node->list); + rcu_read_unlock(); nr_successful_enqueues++; if (unlikely(wdelay)) @@ -203,6 +210,14 @@ fail: } +static +void free_node_cb(struct rcu_head *head) +{ + struct test *node = + caa_container_of(head, struct test, rcu); + free(node); +} + void *thr_dequeuer(void *_count) { unsigned long long *count = _count; @@ -226,11 +241,16 @@ void *thr_dequeuer(void *_count) cmm_smp_mb(); for (;;) { - struct cds_lfq_node_rcu *node; + struct cds_lfq_node_rcu *qnode; + struct test *node; + + rcu_read_lock(); + qnode = cds_lfq_dequeue_rcu(&q); + node = caa_container_of(qnode, struct test, list); + rcu_read_unlock(); - node = cds_lfq_dequeue_rcu(&q); if (node) { - defer_rcu(free, node); + call_rcu(&node->rcu, free_node_cb); nr_successful_dequeues++; } @@ -254,15 +274,18 @@ void *thr_dequeuer(void *_count) void test_end(struct cds_lfq_queue_rcu *q, unsigned long long *nr_dequeues) { - struct cds_lfq_node_rcu *node; + struct cds_lfq_node_rcu *snode; do { - node = cds_lfq_dequeue_rcu(q); - if (node) { + snode = cds_lfq_dequeue_rcu(q); + if (snode) { + struct test *node; + + node = caa_container_of(snode, struct test, list); free(node); /* no more concurrent access */ (*nr_dequeues)++; } - } while (node); + } while (snode); } void show_usage(int argc, char **argv) @@ -356,7 +379,9 @@ 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, call_rcu); + err = create_all_cpu_call_rcu_data(0); + assert(!err); next_aff = 0; @@ -425,6 +450,7 @@ int main(int argc, char **argv) tot_successful_enqueues, tot_successful_dequeues + end_dequeues); + free_all_cpu_call_rcu_data(); free(count_enqueuer); free(count_dequeuer); free(tid_enqueuer);