diff options
author | ylavic <ylavic@13f79535-47bb-0310-9956-ffa450edef68> | 2015-03-19 23:38:38 +0000 |
---|---|---|
committer | ylavic <ylavic@13f79535-47bb-0310-9956-ffa450edef68> | 2015-03-19 23:38:38 +0000 |
commit | 60a8bd9c92c4f3e0447a8be1ab93f5ccae587acf (patch) | |
tree | db6a0ab5bc8d6b81c56cd429c0b9bda4383c15ec /test/testmutexscope.c | |
parent | 9a55fd27564c533249a6c254675b1bd25ee22f5f (diff) | |
download | libapr-60a8bd9c92c4f3e0447a8be1ab93f5ccae587acf.tar.gz |
locks: introduce apr_{thread,proc,global}_mutex_timedlock().
For proc mutexes, the new mechanism APR_LOCK_DEFAULT_TIMED usable at creation time
allows for the best mechanism to be elected (unixes: 1 to 3, or specific: 4 to 7):
1. PROC_PTHREAD if pthread_mutex_timedlock() and pthread_mutex_set_robust_np()
are both available,
2. SYSV if semtimedop() is availale,
3. POSIXSEM if sem_timedwait() is available,
4. BeOS' acquire_sem_etc() if available,
5. NetWare falls back to apr_thread_mutex_timedlock() as for others functions,
6. OS2's DosRequestMutexSem(),
7. Windows' WaitForSingleObject().
Otherwise (like when fcntl and flock only are availble, if that's ever possible),
APR_ENOTIMPL is returned.
For thread mutexes, the new flag APR_THREAD_MUTEX_TIMED, usable at create()
time still, allows to switch to an implementation using a condition variable
and apr_thread_cond_timedwait() when if no native mechanism is available (eg.
NetWare, pthreads but without pthread_mutex_timedlock() available).
On windows, this initializes a WaitForSingleObject()able handle (Mutex) instead
of the fastest (but not timeout-able) CRITICAL_SECTION used by default.
All apr_{thread,proc,global}_mutex_timedlock() functions can take a relative or
absolute time, thanks to the last (boolean) argument.
Test suite updated accordingly.
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@1667900 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/testmutexscope.c')
-rw-r--r-- | test/testmutexscope.c | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/test/testmutexscope.c b/test/testmutexscope.c index 57fcaf5aa..808135773 100644 --- a/test/testmutexscope.c +++ b/test/testmutexscope.c @@ -43,20 +43,22 @@ static apr_pool_t *p; static volatile int counter; typedef enum {TEST_GLOBAL, TEST_PROC} test_mode_e; -static void lock_init(apr_lockmech_e mech, test_mode_e test_mode) +static int lock_init(apr_lockmech_e mech, test_mode_e test_mode) { + apr_status_t rv; if (test_mode == TEST_PROC) { - assert(apr_proc_mutex_create(&proc_mutex, - NULL, - mech, - p) == APR_SUCCESS); + rv = apr_proc_mutex_create(&proc_mutex, + NULL, + mech, + p); } else { - assert(apr_global_mutex_create(&global_mutex, - NULL, - mech, - p) == APR_SUCCESS); + rv = apr_global_mutex_create(&global_mutex, + NULL, + mech, + p); } + return rv; } static void lock_destroy(test_mode_e test_mode) @@ -120,7 +122,17 @@ static void test_mech_mode(apr_lockmech_e mech, const char *mech_name, assert(apr_thread_mutex_create(&thread_mutex, 0, p) == APR_SUCCESS); assert(apr_thread_mutex_lock(thread_mutex) == APR_SUCCESS); - lock_init(mech, test_mode); + rv = lock_init(mech, test_mode); + if (rv != APR_SUCCESS) { + char errmsg[256]; + printf("%s mutexes with mechanism `%s': %s\n", + test_mode == TEST_GLOBAL ? "Global" : "Proc", mech_name, + apr_strerror(rv, errmsg, sizeof errmsg)); + if (rv != APR_ENOTIMPL || mech == APR_LOCK_DEFAULT) { + exit(1); + } + return; + } counter = 0; @@ -142,7 +154,7 @@ static void test_mech_mode(apr_lockmech_e mech, const char *mech_name, apr_sleep(apr_time_from_sec(5)); if (test_mode == TEST_PROC) { - printf(" Mutex mechanism `%s' is %sglobal in scope on this platform.\n", + printf(" mutex mechanism `%s' is %sglobal in scope on this platform.\n", mech_name, counter == 1 ? "" : "not "); } else { @@ -155,7 +167,7 @@ static void test_mech_mode(apr_lockmech_e mech, const char *mech_name, exit(1); } else { - printf(" no problems encountered...\n"); + printf(" no problem encountered...\n"); } } @@ -205,6 +217,7 @@ int main(void) #if APR_HAS_PROC_PTHREAD_SERIALIZE ,{APR_LOCK_PROC_PTHREAD, "proc_pthread"} #endif + ,{APR_LOCK_DEFAULT_TIMED, "default_timed"} }; int i; |