X-Git-Url: http://git.liburcu.org/?p=urcu.git;a=blobdiff_plain;f=test_urcu.c;h=f6be45b1e2769a9f700e4bb0cf0968046db5a2e1;hp=7752e6ed23f5392e69b3bee6b50b0ef9e224f05a;hb=c265818b951224bcde407b1efa14f9daf44949b3;hpb=20bf310ac72677961e55867dd64d058f77e0d7e6 diff --git a/test_urcu.c b/test_urcu.c index 7752e6e..f6be45b 100644 --- a/test_urcu.c +++ b/test_urcu.c @@ -47,6 +47,28 @@ static struct test_array *test_rcu_pointer; #define NR_READ 10 #define NR_WRITE 9 +pthread_mutex_t rcu_copy_mutex = PTHREAD_MUTEX_INITIALIZER; + +void rcu_copy_mutex_lock(void) +{ + int ret; + ret = pthread_mutex_lock(&rcu_copy_mutex); + if (ret) { + perror("Error in pthread mutex lock"); + exit(-1); + } +} + +void rcu_copy_mutex_unlock(void) +{ + int ret; + + ret = pthread_mutex_unlock(&rcu_copy_mutex); + if (ret) { + perror("Error in pthread mutex unlock"); + exit(-1); + } +} void *thr_reader(void *arg) { @@ -61,14 +83,14 @@ void *thr_reader(void *arg) for (i = 0; i < 100000; i++) { for (j = 0; j < 100000000; j++) { - qparity = rcu_read_lock(); + rcu_read_lock(&qparity); local_ptr = rcu_dereference(test_rcu_pointer); if (local_ptr) { assert(local_ptr->a == 8); assert(local_ptr->b == 12); assert(local_ptr->c[55] == 2); } - rcu_read_unlock(qparity); + rcu_read_unlock(&qparity); } } @@ -89,7 +111,7 @@ void *thr_writer(void *arg) for (i = 0; i < 10000000; i++) { new = malloc(sizeof(struct test_array)); - rcu_write_lock(); + rcu_copy_mutex_lock(); old = test_rcu_pointer; if (old) { assert(old->a == 8); @@ -100,7 +122,7 @@ void *thr_writer(void *arg) new->b = 12; new->a = 8; old = urcu_publish_content((void **)&test_rcu_pointer, new); - rcu_write_unlock(); + rcu_copy_mutex_unlock(); /* can be done after unlock */ if (old) { old->a = 0;