apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r553863 - /apr/apr/trunk/test/testatomic.c
Date Fri, 06 Jul 2007 12:31:46 GMT
Author: davi
Date: Fri Jul  6 05:31:45 2007
New Revision: 553863

URL: http://svn.apache.org/viewvc?view=rev&rev=553863
Log:
The test can run faster by relinquishing the processor when the count value
is not the thread pre-value. This change lets increase the number of loops.

Modified:
    apr/apr/trunk/test/testatomic.c

Modified: apr/apr/trunk/test/testatomic.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/test/testatomic.c?view=diff&rev=553863&r1=553862&r2=553863
==============================================================================
--- apr/apr/trunk/test/testatomic.c (original)
+++ apr/apr/trunk/test/testatomic.c Fri Jul  6 05:31:45 2007
@@ -300,15 +300,26 @@
     void (*func)(tbox_t *box);
 };
 
-static void busyloop_set32(tbox_t *tbox)
+static APR_INLINE void busyloop_read32(tbox_t *tbox)
 {
     apr_uint32_t val;
 
     do {
-        do {
-            val = apr_atomic_read32(tbox->mem);
-        } while (val != tbox->preval);
+        val = apr_atomic_read32(tbox->mem);
+
+        if (val != tbox->preval)
+            apr_thread_yield();
+        else
+            break;
+    } while (1);
+}
+
+static void busyloop_set32(tbox_t *tbox)
+{
+    apr_uint32_t val;
 
+    do {
+        busyloop_read32(tbox);
         apr_atomic_set32(tbox->mem, tbox->postval);
     } while (--tbox->loop);
 }
@@ -318,12 +329,8 @@
     apr_uint32_t val;
 
     do {
-        do {
-            val = apr_atomic_read32(tbox->mem);
-        } while (val != tbox->preval);
-
+        busyloop_read32(tbox);
         val = apr_atomic_add32(tbox->mem, tbox->postval);
-
         apr_thread_mutex_lock(thread_lock);
         ABTS_INT_EQUAL(tbox->tc, val, tbox->preval);
         apr_thread_mutex_unlock(thread_lock);
@@ -335,10 +342,7 @@
     apr_uint32_t val;
 
     do {
-        do {
-            val = apr_atomic_read32(tbox->mem);
-        } while (val != tbox->preval);
-
+        busyloop_read32(tbox);
         apr_atomic_sub32(tbox->mem, tbox->postval);
     } while (--tbox->loop);
 }
@@ -348,12 +352,8 @@
     apr_uint32_t val;
 
     do {
-        do {
-            val = apr_atomic_read32(tbox->mem);
-        } while (val != tbox->preval);
-
+        busyloop_read32(tbox);
         val = apr_atomic_inc32(tbox->mem);
-
         apr_thread_mutex_lock(thread_lock);
         ABTS_INT_EQUAL(tbox->tc, val, tbox->preval);
         apr_thread_mutex_unlock(thread_lock);
@@ -365,12 +365,8 @@
     apr_uint32_t val;
 
     do {
-        do {
-            val = apr_atomic_read32(tbox->mem);
-        } while (val != tbox->preval);
-
+        busyloop_read32(tbox);
         val = apr_atomic_dec32(tbox->mem);
-
         apr_thread_mutex_lock(thread_lock);
         ABTS_INT_NEQUAL(tbox->tc, val, 0);
         apr_thread_mutex_unlock(thread_lock);
@@ -384,7 +380,12 @@
     do {
         do {
             val = apr_atomic_cas32(tbox->mem, tbox->postval, tbox->preval);
-        } while (val != tbox->preval);
+
+            if (val != tbox->preval)
+                apr_thread_yield();
+            else
+                break;
+        } while (1);
     } while (--tbox->loop);
 }
 
@@ -393,12 +394,8 @@
     apr_uint32_t val;
 
     do {
-        do {
-            val = apr_atomic_read32(tbox->mem);
-        } while (val != tbox->preval);
-
+        busyloop_read32(tbox);
         val = apr_atomic_xchg32(tbox->mem, tbox->postval);
-
         apr_thread_mutex_lock(thread_lock);
         ABTS_INT_EQUAL(tbox->tc, val, tbox->preval);
         apr_thread_mutex_unlock(thread_lock);
@@ -431,7 +428,7 @@
     for (i = 0; i < NUM_THREADS; i++) {
         tbox[i].tc = tc;
         tbox[i].mem = &count;
-        tbox[i].loop = 5;
+        tbox[i].loop = 50;
     }
 
     tbox[0].preval = 98;



Mime
View raw message