apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jor...@apache.org
Subject svn commit: r397188 - /apr/apr/trunk/test/testprocmutex.c
Date Wed, 26 Apr 2006 12:33:23 GMT
Author: jorton
Date: Wed Apr 26 05:33:19 2006
New Revision: 397188

URL: http://svn.apache.org/viewcvs?rev=397188&view=rev
Log:
* test/testprocmutex.c (make_child): Take trylock parameter.
(test_exclusive): Run tests for both normal locking and trylock

Submitted by: Chris Darroch <chrisd pearsoncmg.com>
PR: 39289

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

Modified: apr/apr/trunk/test/testprocmutex.c
URL: http://svn.apache.org/viewcvs/apr/apr/trunk/test/testprocmutex.c?rev=397188&r1=397187&r2=397188&view=diff
==============================================================================
--- apr/apr/trunk/test/testprocmutex.c (original)
+++ apr/apr/trunk/test/testprocmutex.c Wed Apr 26 05:33:19 2006
@@ -31,6 +31,7 @@
 #define MAX_ITER 200
 #define CHILDREN 6
 #define MAX_COUNTER (MAX_ITER * CHILDREN)
+#define MAX_WAIT_USEC (1000*1000)
 
 static apr_proc_mutex_t *proc_lock;
 static volatile int *x;
@@ -42,7 +43,7 @@
     return n+1;
 }
 
-static void make_child(abts_case *tc, apr_proc_t **proc, apr_pool_t *p)
+static void make_child(abts_case *tc, int trylock, apr_proc_t **proc, apr_pool_t *p)
 {
     apr_status_t rv;
 
@@ -68,8 +69,22 @@
             exit(1);
 
         do {
-            if (apr_proc_mutex_lock(proc_lock))
-                exit(1);
+            if (trylock) {
+                int wait_usec = 0;
+
+                while ((rv = apr_proc_mutex_trylock(proc_lock))) {
+                    if (!APR_STATUS_IS_EBUSY(rv))
+                        exit(1);
+                    if (++wait_usec >= MAX_WAIT_USEC)
+                        exit(1);
+                    apr_sleep(1);
+                }
+            }
+            else {
+                if (apr_proc_mutex_lock(proc_lock))
+                    exit(1);
+            }
+
             i++;
             *x = increment(*x);
             if (apr_proc_mutex_unlock(proc_lock))
@@ -106,12 +121,33 @@
         return;
  
     for (n = 0; n < CHILDREN; n++)
-        make_child(tc, &child[n], p);
+        make_child(tc, 0, &child[n], p);
 
     for (n = 0; n < CHILDREN; n++)
         await_child(tc, child[n]);
     
     ABTS_ASSERT(tc, "Locks don't appear to work", *x == MAX_COUNTER);
+
+    rv = apr_proc_mutex_trylock(proc_lock);
+    if (rv == APR_ENOTIMPL) {
+        ABTS_NOT_IMPL(tc, "apr_proc_mutex_trylock not implemented");
+        return;
+    }
+    APR_ASSERT_SUCCESS(tc, "check for trylock", rv);
+
+    rv = apr_proc_mutex_unlock(proc_lock);
+    APR_ASSERT_SUCCESS(tc, "unlock after trylock check", rv);
+
+    *x = 0;
+
+    for (n = 0; n < CHILDREN; n++)
+        make_child(tc, 1, &child[n], p);
+
+    for (n = 0; n < CHILDREN; n++)
+        await_child(tc, child[n]);
+    
+    ABTS_ASSERT(tc, "Locks don't appear to work with trylock",
+                *x == MAX_COUNTER);
 }
 #endif
 



Mime
View raw message