--- test/testprocmutex.c.orig 2006-04-12 11:23:22.920556747 -0400 +++ test/testprocmutex.c 2006-04-12 13:54:07.863121812 -0400 @@ -31,9 +31,11 @@ #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; +static int trylock_flag = 0; /* a slower more racy way to implement (*x)++ */ static int increment(int n) @@ -49,7 +51,7 @@ *proc = apr_pcalloc(p, sizeof(**proc)); /* slight delay to allow things to settle */ - apr_sleep (1); + apr_sleep(1); rv = apr_proc_fork(*proc, p); if (rv == APR_INCHILD) { @@ -68,10 +70,25 @@ exit(1); do { - if (apr_proc_mutex_lock(proc_lock)) - exit(1); + if (trylock_flag) { + 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)) exit(1); } while (i < MAX_ITER); @@ -104,7 +121,10 @@ APR_ASSERT_SUCCESS(tc, "create the mutex", rv); if (rv != APR_SUCCESS) return; - + + trylock_flag = 0; + *x = 0; + for (n = 0; n < CHILDREN; n++) make_child(tc, &child[n], p); @@ -112,6 +132,28 @@ 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); + + trylock_flag = 1; + *x = 0; + + for (n = 0; n < CHILDREN; n++) + make_child(tc, &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