Don't mix pthread sleepable lock with busy-waiting locking.
authorMathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Wed, 8 Apr 2009 00:35:46 +0000 (20:35 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Wed, 8 Apr 2009 00:35:46 +0000 (20:35 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
test_urcu.c
urcu.c

index 3a28474561977675c6932663055c3cb8d2e2fc19..129b33abdb4a3dd6d2e0bea6f567c0caad2fd611 100644 (file)
@@ -47,14 +47,25 @@ static struct test_array *test_rcu_pointer;
 static unsigned long duration;
 static time_t start_time;
 static unsigned long __thread duration_interval;
-#define DURATION_TEST_DELAY 100
+#define DURATION_TEST_DELAY_WRITE 4
+#define DURATION_TEST_DELAY_READ 100
 
 /*
  * returns 0 if test should end.
  */
-static int test_duration(void)
+static int test_duration_write(void)
 {
-       if (duration_interval++ >= DURATION_TEST_DELAY) {
+       if (duration_interval++ >= DURATION_TEST_DELAY_WRITE) {
+               duration_interval = 0;
+               if (time(NULL) - start_time >= duration)
+                       return 0;
+       }
+       return 1;
+}
+
+static int test_duration_read(void)
+{
+       if (duration_interval++ >= DURATION_TEST_DELAY_READ) {
                duration_interval = 0;
                if (time(NULL) - start_time >= duration)
                        return 0;
@@ -145,7 +156,7 @@ void *thr_reader(void *_count)
                        assert(local_ptr->a == 8);
                rcu_read_unlock();
                nr_reads++;
-               if (!test_duration())
+               if (!test_duration_read())
                        break;
        }
 
@@ -180,7 +191,7 @@ void *thr_writer(void *_count)
                        old->a = 0;
                test_array_free(old);
                nr_writes++;
-               if (!test_duration())
+               if (!test_duration_write())
                        break;
                if (!no_writer_delay)
                        usleep(1);
@@ -270,6 +281,7 @@ int main(int argc, char **argv)
                        exit(1);
                tot_writes += count_writer[i];
        }
+       
        printf("total number of reads : %llu, writes %llu\n", tot_reads,
               tot_writes);
        test_array_free(test_rcu_pointer);
diff --git a/urcu.c b/urcu.c
index 5e2d2afff5641c57a80548c1f78469c52ccf7b09..475bebf526dfd1b9cc8cf78b87d8804ded7a1b6f 100644 (file)
--- a/urcu.c
+++ b/urcu.c
@@ -54,12 +54,17 @@ static int sig_done;
 
 void internal_urcu_lock(void)
 {
+#if 0
        int ret;
+       /* Mutex sleeping does not play well with busy-waiting loop. */
        ret = pthread_mutex_lock(&urcu_mutex);
        if (ret) {
                perror("Error in pthread mutex lock");
                exit(-1);
        }
+#endif
+       while (pthread_mutex_trylock(&urcu_mutex) != 0)
+               cpu_relax();
 }
 
 void internal_urcu_unlock(void)
This page took 0.026416 seconds and 4 git commands to generate.