X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=tests%2Ftest_urcu_lfs.c;h=9af846d1c782a724caeb41306e39aa29352ac0c4;hb=cb8818f01ed341f21d9b6467365a66fda3fc6856;hp=88bf65d09bd533bf19139a4028e68e990e43ea64;hpb=bd252a04bbbb163aa4d8864b1e1e5a3a4d9d0892;p=urcu.git diff --git a/tests/test_urcu_lfs.c b/tests/test_urcu_lfs.c index 88bf65d..9af846d 100644 --- a/tests/test_urcu_lfs.c +++ b/tests/test_urcu_lfs.c @@ -1,9 +1,9 @@ /* * test_urcu_lfs.c * - * Userspace RCU library - example RCU-based lock-free stack + * Userspace RCU library - example lock-free stack * - * Copyright February 2010 - Mathieu Desnoyers + * Copyright 2010-2012 - Mathieu Desnoyers * Copyright February 2010 - Paolo Bonzini * * This program is free software; you can redistribute it and/or modify @@ -67,7 +67,6 @@ static inline pid_t gettid(void) #endif #include #include -#include static volatile int test_go, test_stop; @@ -78,9 +77,9 @@ static unsigned long duration; /* read-side C.S. duration, in loops */ static unsigned long wdelay; -static inline void loop_sleep(unsigned long l) +static inline void loop_sleep(unsigned long loops) { - while(l-- != 0) + while (loops-- != 0) caa_cpu_relax(); } @@ -106,9 +105,10 @@ typedef unsigned long cpu_set_t; static void set_affinity(void) { +#if HAVE_SCHED_SETAFFINITY cpu_set_t mask; - int cpu; - int ret; + int cpu, ret; +#endif /* HAVE_SCHED_SETAFFINITY */ if (!use_affinity) return; @@ -159,11 +159,11 @@ static unsigned int nr_enqueuers; static unsigned int nr_dequeuers; struct test { - struct cds_lfs_node_rcu list; + struct cds_lfs_node list; struct rcu_head rcu; }; -static struct cds_lfs_stack_rcu s; +static struct cds_lfs_stack s; void *thr_enqueuer(void *_count) { @@ -185,9 +185,8 @@ void *thr_enqueuer(void *_count) struct test *node = malloc(sizeof(*node)); if (!node) goto fail; - cds_lfs_node_init_rcu(&node->list); - /* No rcu read-side is needed for push */ - cds_lfs_push_rcu(&s, &node->list); + cds_lfs_node_init(&node->list); + cds_lfs_push(&s, &node->list); URCU_TLS(nr_successful_enqueues)++; if (caa_unlikely(wdelay)) @@ -221,18 +220,12 @@ void free_node_cb(struct rcu_head *head) 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(); - ret = rcu_defer_register_thread(); - if (ret) { - printf("Error in rcu_defer_register_thread\n"); - exit(-1); - } rcu_register_thread(); while (!test_go) @@ -241,14 +234,15 @@ void *thr_dequeuer(void *_count) cmm_smp_mb(); for (;;) { - struct cds_lfs_node_rcu *snode; - struct test *node; + struct cds_lfs_node *snode; rcu_read_lock(); - snode = cds_lfs_pop_rcu(&s); - node = caa_container_of(snode, struct test, list); + snode = cds_lfs_pop(&s); rcu_read_unlock(); - if (node) { + if (snode) { + struct test *node; + + node = caa_container_of(snode, struct test, list); call_rcu(&node->rcu, free_node_cb); URCU_TLS(nr_successful_dequeues)++; } @@ -260,7 +254,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", @@ -271,12 +264,12 @@ void *thr_dequeuer(void *_count) return ((void*)2); } -void test_end(struct cds_lfs_stack_rcu *s, unsigned long long *nr_dequeues) +void test_end(struct cds_lfs_stack *s, unsigned long long *nr_dequeues) { - struct cds_lfs_node_rcu *snode; + struct cds_lfs_node *snode; do { - snode = cds_lfs_pop_rcu(s); + snode = cds_lfs_pop(s); if (snode) { struct test *node; @@ -378,7 +371,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_lfs_init_rcu(&s); + cds_lfs_init(&s); err = create_all_cpu_call_rcu_data(0); if (err) { printf("Per-CPU call_rcu() worker threads unavailable. Using default global worker thread.\n");