X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=tests%2Ftest_urcu_assign.c;h=0d9ef853db8eb88b7b0fbe1650c6fc09201fec50;hb=dd51e0ad14ab677d0fab45b492150adce2ee863e;hp=a73fc23892aa37961de60c409d6b2dbae0d11d49;hpb=92e8d9d64a97e2d098cefa223208b2d18118194e;p=urcu.git diff --git a/tests/test_urcu_assign.c b/tests/test_urcu_assign.c index a73fc23..0d9ef85 100644 --- a/tests/test_urcu_assign.c +++ b/tests/test_urcu_assign.c @@ -31,12 +31,15 @@ #include #include #include -#include #include #include #include +#ifdef __linux__ +#include +#endif + /* hardcoded number of CPUs */ #define NR_CPUS 16384 @@ -183,7 +186,8 @@ void rcu_copy_mutex_unlock(void) /* * malloc/free are reusing memory areas too quickly, which does not let us * test races appropriately. Use a large circular array for allocations. - * ARRAY_SIZE is larger than nr_writers, which insures we never run over our tail. + * ARRAY_SIZE is larger than nr_writers, and we keep the mutex across + * both alloc and free, which insures we never run over our tail. */ #define ARRAY_SIZE (1048576 * nr_writers) #define ARRAY_POISON 0xDEADBEEF @@ -195,7 +199,6 @@ static struct test_array *test_array_alloc(void) struct test_array *ret; int index; - rcu_copy_mutex_lock(); index = array_index % ARRAY_SIZE; assert(test_array[index].a == ARRAY_POISON || test_array[index].a == 0); @@ -203,7 +206,6 @@ static struct test_array *test_array_alloc(void) array_index++; if (array_index == ARRAY_SIZE) array_index = 0; - rcu_copy_mutex_unlock(); return ret; } @@ -211,9 +213,7 @@ static void test_array_free(struct test_array *ptr) { if (!ptr) return; - rcu_copy_mutex_lock(); ptr->a = ARRAY_POISON; - rcu_copy_mutex_unlock(); } void *thr_reader(void *_count) @@ -272,18 +272,18 @@ void *thr_writer(void *_count) cmm_smp_mb(); for (;;) { + rcu_copy_mutex_lock(); new = test_array_alloc(); new->a = 8; - rcu_copy_mutex_lock(); old = test_rcu_pointer; rcu_assign_pointer(test_rcu_pointer, new); if (unlikely(wduration)) loop_sleep(wduration); - rcu_copy_mutex_unlock(); synchronize_rcu(); if (old) old->a = 0; test_array_free(old); + rcu_copy_mutex_unlock(); nr_writes++; if (unlikely(!test_duration_write())) break;