diff options
author | Yann Ylavic <ylavic@apache.org> | 2017-04-07 00:01:16 +0000 |
---|---|---|
committer | Yann Ylavic <ylavic@apache.org> | 2017-04-07 00:01:16 +0000 |
commit | f7b5a5f20e3edfb8ef2f4077147acb0bf17b3fab (patch) | |
tree | 5c5c8a818d677acc7cf00a9b3cd5bfbf9a669977 | |
parent | 0ea4c151aa5f650867a0afa3e92f90fc1bdbf114 (diff) | |
download | apr-f7b5a5f20e3edfb8ef2f4077147acb0bf17b3fab.tar.gz |
locks: follow up to r1667900.
Axe the 'absolute' argument of apr_{thread,proc,global}_mutex_timedlock()
which was confusing, hence 'timeout' is always relative now.
It still makes sense (to me) to handle a negative timeout as INFINITE, a nul
one as IMMEDIATE, and a positive one as an upper bound timeout (like most if
not all of the underlying system calls...).
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1790488 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | include/apr_global_mutex.h | 6 | ||||
-rw-r--r-- | include/apr_proc_mutex.h | 6 | ||||
-rw-r--r-- | include/apr_thread_mutex.h | 6 | ||||
-rw-r--r-- | include/arch/unix/apr_arch_proc_mutex.h | 2 | ||||
-rw-r--r-- | locks/beos/proc_mutex.c | 27 | ||||
-rw-r--r-- | locks/beos/thread_mutex.c | 27 | ||||
-rw-r--r-- | locks/netware/proc_mutex.c | 5 | ||||
-rw-r--r-- | locks/netware/thread_mutex.c | 26 | ||||
-rw-r--r-- | locks/os2/proc_mutex.c | 23 | ||||
-rw-r--r-- | locks/os2/thread_mutex.c | 26 | ||||
-rw-r--r-- | locks/unix/global_mutex.c | 21 | ||||
-rw-r--r-- | locks/unix/proc_mutex.c | 64 | ||||
-rw-r--r-- | locks/unix/thread_mutex.c | 59 | ||||
-rw-r--r-- | locks/win32/proc_mutex.c | 12 | ||||
-rw-r--r-- | locks/win32/thread_mutex.c | 12 | ||||
-rw-r--r-- | test/testlock.c | 4 | ||||
-rw-r--r-- | test/testlockperf.c | 2 | ||||
-rw-r--r-- | test/testprocmutex.c | 6 |
18 files changed, 128 insertions, 206 deletions
diff --git a/include/apr_global_mutex.h b/include/apr_global_mutex.h index f6deb8d17..183f31083 100644 --- a/include/apr_global_mutex.h +++ b/include/apr_global_mutex.h @@ -114,12 +114,10 @@ APR_DECLARE(apr_status_t) apr_global_mutex_trylock(apr_global_mutex_t *mutex); * Attempt to acquire the lock for the given mutex until timeout expires. * If the acquisition time outs, the call returns with APR_TIMEUP. * @param mutex the mutex on which to attempt the lock acquiring. - * @param timeout the absolute time or relative timeout (microseconds) - * @param absolute whether the timeout given is absolute (!0) or relative (0) + * @param timeout the relative timeout (microseconds) */ APR_DECLARE(apr_status_t) apr_global_mutex_timedlock(apr_global_mutex_t *mutex, - apr_time_t timeout, - int absolute); + apr_time_t timeout); /** * Release the lock for the given mutex. diff --git a/include/apr_proc_mutex.h b/include/apr_proc_mutex.h index 15312b2bd..4c0f92bc0 100644 --- a/include/apr_proc_mutex.h +++ b/include/apr_proc_mutex.h @@ -119,12 +119,10 @@ APR_DECLARE(apr_status_t) apr_proc_mutex_trylock(apr_proc_mutex_t *mutex); * Attempt to acquire the lock for the given mutex until timeout expires. * If the acquisition time outs, the call returns with APR_TIMEUP. * @param mutex the mutex on which to attempt the lock acquiring. - * @param timeout the absolute time or relative timeout (microseconds) - * @param absolute whether the timeout given is absolute (!0) or relative (0) + * @param timeout the relative timeout (microseconds) */ APR_DECLARE(apr_status_t) apr_proc_mutex_timedlock(apr_proc_mutex_t *mutex, - apr_time_t timeout, - int absolute); + apr_time_t timeout); /** * Release the lock for the given mutex. diff --git a/include/apr_thread_mutex.h b/include/apr_thread_mutex.h index 5dd729d07..efc62f65a 100644 --- a/include/apr_thread_mutex.h +++ b/include/apr_thread_mutex.h @@ -87,12 +87,10 @@ APR_DECLARE(apr_status_t) apr_thread_mutex_trylock(apr_thread_mutex_t *mutex); * Attempt to acquire the lock for the given mutex until timeout expires. * If the acquisition time outs, the call returns with APR_TIMEUP. * @param mutex the mutex on which to attempt the lock acquiring. - * @param timeout the absolute time or relative timeout (microseconds) - * @param absolute whether the timeout given is absolute (!0) or relative (0) + * @param timeout the relative timeout (microseconds) */ APR_DECLARE(apr_status_t) apr_thread_mutex_timedlock(apr_thread_mutex_t *mutex, - apr_time_t timeout, - int absolute); + apr_time_t timeout); /** * Release the lock for the given mutex. diff --git a/include/arch/unix/apr_arch_proc_mutex.h b/include/arch/unix/apr_arch_proc_mutex.h index 998824847..86aaab5dc 100644 --- a/include/arch/unix/apr_arch_proc_mutex.h +++ b/include/arch/unix/apr_arch_proc_mutex.h @@ -70,7 +70,7 @@ struct apr_proc_mutex_unix_lock_methods_t { apr_status_t (*create)(apr_proc_mutex_t *, const char *); apr_status_t (*acquire)(apr_proc_mutex_t *); apr_status_t (*tryacquire)(apr_proc_mutex_t *); - apr_status_t (*timedacquire)(apr_proc_mutex_t *, apr_time_t, int); + apr_status_t (*timedacquire)(apr_proc_mutex_t *, apr_time_t); apr_status_t (*release)(apr_proc_mutex_t *); apr_status_t (*cleanup)(void *); apr_status_t (*child_init)(apr_proc_mutex_t **, apr_pool_t *, const char *); diff --git a/locks/beos/proc_mutex.c b/locks/beos/proc_mutex.c index 1b468714c..dba07c0a5 100644 --- a/locks/beos/proc_mutex.c +++ b/locks/beos/proc_mutex.c @@ -109,33 +109,20 @@ APR_DECLARE(apr_status_t) apr_proc_mutex_trylock(apr_proc_mutex_t *mutex) } APR_DECLARE(apr_status_t) apr_proc_mutex_timedlock(apr_proc_mutex_t *mutex, - apr_time_t timeout, - int absolute) + apr_time_t timeout) { int32 stat; if (atomic_add(&mutex->LockCount, 1) > 0) { - if (timeout < 0) { + if (!timeout) { + stat = B_TIMED_OUT; + } + else if (timeout < 0) { stat = acquire_sem(mutex->Lock); } else { - int flag = 0; - if (timeout > 0) { - if (absolute) { - apr_time_t now = apr_time_now(); - if (timeout > now) { - timeout -= now; - } - else { - timeout = 0; - } - flag = B_ABSOLUTE_TIMEOUT; - } - else { - flag = B_RELATIVE_TIMEOUT; - } - } - stat = acquire_sem_etc(mutex->Lock, 1, flag, timeout); + stat = acquire_sem_etc(mutex->Lock, 1, B_RELATIVE_TIMEOUT, + timeout); } if (stat < B_NO_ERROR) { atomic_add(&mutex->LockCount, -1); diff --git a/locks/beos/thread_mutex.c b/locks/beos/thread_mutex.c index 2fa1bc70b..62e81319e 100644 --- a/locks/beos/thread_mutex.c +++ b/locks/beos/thread_mutex.c @@ -132,8 +132,7 @@ APR_DECLARE(apr_status_t) apr_thread_mutex_trylock(apr_thread_mutex_t *mutex) } APR_DECLARE(apr_status_t) apr_thread_mutex_timedlock(apr_thread_mutex_t *mutex, - apr_time_t timeout, - int absolute) + apr_time_t timeout) { int32 stat; thread_id me = find_thread(NULL); @@ -144,27 +143,15 @@ APR_DECLARE(apr_status_t) apr_thread_mutex_timedlock(apr_thread_mutex_t *mutex, } if (atomic_add(&mutex->LockCount, 1) > 0) { - if (timeout < 0) { + if (!timeout) { + stat = B_TIMED_OUT; + } + else if (timeout < 0) { stat = acquire_sem(mutex->Lock); } else { - int flag = 0; - if (timeout > 0) { - if (absolute) { - apr_time_t now = apr_time_now(); - if (timeout > now) { - timeout -= now; - } - else { - timeout = 0; - } - flag = B_ABSOLUTE_TIMEOUT; - } - else { - flag = B_RELATIVE_TIMEOUT; - } - } - stat = acquire_sem_etc(mutex->Lock, 1, flag, timeout); + stat = acquire_sem_etc(mutex->Lock, 1, B_RELATIVE_TIMEOUT, + timeout); } if (stat < B_NO_ERROR) { atomic_add(&mutex->LockCount, -1); diff --git a/locks/netware/proc_mutex.c b/locks/netware/proc_mutex.c index 231f242b4..01cd7cfec 100644 --- a/locks/netware/proc_mutex.c +++ b/locks/netware/proc_mutex.c @@ -73,11 +73,10 @@ APR_DECLARE(apr_status_t) apr_proc_mutex_trylock(apr_proc_mutex_t *mutex) } APR_DECLARE(apr_status_t) apr_proc_mutex_timedlock(apr_proc_mutex_t *mutex, - apr_time_t timeout, - int absolute) + apr_time_t timeout) { if (mutex) - return apr_thread_mutex_timedlock(mutex->mutex, timeout, absolute); + return apr_thread_mutex_timedlock(mutex->mutex, timeout); return APR_ENOLOCK; } diff --git a/locks/netware/thread_mutex.c b/locks/netware/thread_mutex.c index c634edfac..ecb0112f4 100644 --- a/locks/netware/thread_mutex.c +++ b/locks/netware/thread_mutex.c @@ -112,30 +112,26 @@ APR_DECLARE(apr_status_t) apr_thread_mutex_trylock(apr_thread_mutex_t *mutex) } APR_DECLARE(apr_status_t) apr_thread_mutex_timedlock(apr_thread_mutex_t *mutex, - apr_time_t timeout, - int absolute) + apr_time_t timeout) { if (mutex->cond) { apr_status_t rv; NXLock(mutex->mutex); if (mutex->locked) { - mutex->num_waiters++; - if (timeout < 0) { - rv = apr_thread_cond_wait(mutex->cond, mutex); + if (!timeout) { + rv = APR_TIMEUP; } else { - if (absolute) { - apr_time_t now = apr_time_now(); - if (timeout > now) { - timeout -= now; - } - else { - timeout = 0; - } + mutex->num_waiters++; + if (timeout < 0) { + rv = apr_thread_cond_wait(mutex->cond, mutex); + } + else { + rv = apr_thread_cond_timedwait(mutex->cond, mutex, + timeout); } - rv = apr_thread_cond_timedwait(mutex->cond, mutex, timeout); + mutex->num_waiters--; } - mutex->num_waiters--; } else { mutex->locked = 1; diff --git a/locks/os2/proc_mutex.c b/locks/os2/proc_mutex.c index 847f775da..2fe75afa0 100644 --- a/locks/os2/proc_mutex.c +++ b/locks/os2/proc_mutex.c @@ -156,35 +156,24 @@ APR_DECLARE(apr_status_t) apr_proc_mutex_trylock(apr_proc_mutex_t *mutex) mutex->lock_count++; } - return APR_FROM_OS_ERROR(rc); + return (rc == ERROR_TIMEOUT) ? APR_EBUSY : APR_FROM_OS_ERROR(rc); } APR_DECLARE(apr_status_t) apr_proc_mutex_timedlock(apr_proc_mutex_t *mutex, - apr_time_t timeout, - int absolute) + apr_time_t timeout) { ULONG rc; if (timeout < 0) { rc = DosRequestMutexSem(mutex->hMutex, SEM_INDEFINITE_WAIT); } + else if (!timeout) { + rc = DosRequestMutexSem(mutex->hMutex, SEM_IMMEDIATE_RETURN); + } else { - if (absolute) { - apr_time_t now = apr_time_now(); - if (timeout > now) { - timeout -= now; - } - else { - timeout = 0; - } - } - rc = DosRequestMutexSem(mutex->hMutex, apr_time_as_msec(timeout)); - if (rc == ERROR_TIMEOUT) { - return APR_TIMEUP; - } } if (rc == 0) { @@ -192,7 +181,7 @@ APR_DECLARE(apr_status_t) apr_proc_mutex_timedlock(apr_proc_mutex_t *mutex, mutex->lock_count++; } - return APR_FROM_OS_ERROR(rc); + return (rc == ERROR_TIMEOUT) ? APR_TIMEUP : APR_FROM_OS_ERROR(rc); } diff --git a/locks/os2/thread_mutex.c b/locks/os2/thread_mutex.c index fa2d2c1f6..fa79ee7a4 100644 --- a/locks/os2/thread_mutex.c +++ b/locks/os2/thread_mutex.c @@ -67,41 +67,27 @@ APR_DECLARE(apr_status_t) apr_thread_mutex_trylock(apr_thread_mutex_t *mutex) { ULONG rc = DosRequestMutexSem(mutex->hMutex, SEM_IMMEDIATE_RETURN); - if (rc == ERROR_TIMEOUT) { - return APR_EBUSY; - } - - return APR_FROM_OS_ERROR(rc); + return (rc == ERROR_TIMEOUT) ? APR_EBUSY : APR_FROM_OS_ERROR(rc); } APR_DECLARE(apr_status_t) apr_thread_mutex_timedlock(apr_thread_mutex_t *mutex, - apr_time_t timeout, - int absolute) + apr_time_t timeout) { ULONG rc; if (timeout < 0) { rc = DosRequestMutexSem(mutex->hMutex, SEM_INDEFINITE_WAIT); } + else if (!timeout) { + rc = DosRequestMutexSem(mutex->hMutex, SEM_IMMEDIATE_RETURN); + } else { - if (absolute) { - apr_time_t now = apr_time_now(); - if (timeout > now) { - timeout -= now; - } - else { - timeout = 0; - } - } rc = DosRequestMutexSem(mutex->hMutex, apr_time_as_msec(timeout)); - if (rc == ERROR_TIMEOUT) { - return APR_TIMEUP; - } } - return APR_FROM_OS_ERROR(rc); + return (rc == ERROR_TIMEOUT) ? APR_TIMEUP : APR_FROM_OS_ERROR(rc); } diff --git a/locks/unix/global_mutex.c b/locks/unix/global_mutex.c index b343e23ad..9aa213eb2 100644 --- a/locks/unix/global_mutex.c +++ b/locks/unix/global_mutex.c @@ -143,27 +143,30 @@ APR_DECLARE(apr_status_t) apr_global_mutex_trylock(apr_global_mutex_t *mutex) } APR_DECLARE(apr_status_t) apr_global_mutex_timedlock(apr_global_mutex_t *mutex, - apr_time_t timeout, - int absolute) + apr_time_t timeout) { apr_status_t rv; #if APR_HAS_THREADS if (mutex->thread_mutex) { - if (timeout >= 0 && !absolute) { - timeout += apr_time_now(); - absolute = 1; + apr_time_t expiry = 0; + if (timeout > 0) { + expiry = apr_time_now() + timeout; } - rv = apr_thread_mutex_timedlock(mutex->thread_mutex, timeout, - absolute); + rv = apr_thread_mutex_timedlock(mutex->thread_mutex, timeout); if (rv != APR_SUCCESS) { return rv; } + if (expiry) { + timeout = expiry - apr_time_now(); + if (timeout < 0) { + timeout = 0; + } + } } #endif /* APR_HAS_THREADS */ - rv = apr_proc_mutex_timedlock(mutex->proc_mutex, timeout, - absolute); + rv = apr_proc_mutex_timedlock(mutex->proc_mutex, timeout); #if APR_HAS_THREADS if (rv != APR_SUCCESS) { diff --git a/locks/unix/proc_mutex.c b/locks/unix/proc_mutex.c index 435adc9cd..b181da5a6 100644 --- a/locks/unix/proc_mutex.c +++ b/locks/unix/proc_mutex.c @@ -60,16 +60,9 @@ static apr_status_t proc_mutex_no_perms_set(apr_proc_mutex_t *mutex, && !defined(HAVE_PTHREAD_MUTEX_TIMEDLOCK) \ && !defined(HAVE_PTHREAD_CONDATTR_SETPSHARED)) static apr_status_t proc_mutex_spinsleep_timedacquire(apr_proc_mutex_t *mutex, - apr_time_t timeout, - int absolute) + apr_time_t timeout) { apr_status_t rv; - if (absolute) { - timeout -= apr_time_now(); - if (timeout < 0) { - timeout = 0; - } - } if (timeout < 0) { rv = apr_proc_mutex_lock(mutex); } @@ -229,19 +222,20 @@ static apr_status_t proc_mutex_posix_tryacquire(apr_proc_mutex_t *mutex) #if defined(HAVE_SEM_TIMEDWAIT) static apr_status_t proc_mutex_posix_timedacquire(apr_proc_mutex_t *mutex, - apr_time_t timeout, - int absolute) + apr_time_t timeout) { if (timeout < 0) { return proc_mutex_posix_acquire(mutex); } + else if (!timeout) { + apr_status_t rv = proc_mutex_posix_tryacquire(mutex); + return (rv == APR_EBUSY) ? APR_TIMEUP : rv; + } else { int rc; struct timespec abstime; - if (!absolute) { - timeout += apr_time_now(); - } + timeout += apr_time_now(); abstime.tv_sec = apr_time_sec(timeout); abstime.tv_nsec = apr_time_usec(timeout) * 1000; /* nanoseconds */ @@ -386,23 +380,22 @@ static apr_status_t proc_mutex_sysv_tryacquire(apr_proc_mutex_t *mutex) #if defined(HAVE_SEMTIMEDOP) static apr_status_t proc_mutex_sysv_timedacquire(apr_proc_mutex_t *mutex, - apr_time_t timeout, - int absolute) + apr_time_t timeout) { if (timeout < 0) { return proc_mutex_sysv_acquire(mutex); } + else if (!timeout) { + apr_status_t rv = proc_mutex_sysv_tryacquire(mutex); + return (rv == APR_EBUSY) ? APR_TIMEUP : rv; + } else { int rc; struct timespec reltime; - if (absolute) { - timeout -= apr_time_now(); - if (timeout < 0) { - return proc_mutex_sysv_tryacquire(mutex); - } - } + reltime.tv_sec = apr_time_sec(timeout); reltime.tv_nsec = apr_time_usec(timeout) * 1000; /* nanoseconds */ + do { rc = semtimedop(mutex->os.crossproc, &proc_mutex_op_on, 1, &reltime); @@ -517,8 +510,7 @@ typedef struct { static apr_status_t proc_mutex_pthread_timedacquire(apr_proc_mutex_t *mutex, - apr_time_t timeout, - int absolute); + apr_time_t timeout); static APR_INLINE int proc_pthread_mutex_inc(apr_proc_mutex_t *mutex) { @@ -700,21 +692,20 @@ static apr_status_t proc_mutex_pthread_child_init(apr_proc_mutex_t **mutex, static apr_status_t proc_mutex_pthread_acquire(apr_proc_mutex_t *mutex) { - return proc_mutex_pthread_timedacquire(mutex, -1, 0); + return proc_mutex_pthread_timedacquire(mutex, -1); } static apr_status_t proc_mutex_pthread_tryacquire(apr_proc_mutex_t *mutex) { - apr_status_t rv = proc_mutex_pthread_timedacquire(mutex, 0, 0); + apr_status_t rv = proc_mutex_pthread_timedacquire(mutex, 0); return (rv == APR_TIMEUP) ? APR_EBUSY : rv; } static apr_status_t proc_mutex_pthread_timedacquire(apr_proc_mutex_t *mutex, - apr_time_t timeout, - int absolute) + apr_time_t timeout) { #if !APR_USE_PROC_PTHREAD_MUTEX_COND && !defined(HAVE_PTHREAD_MUTEX_TIMEDLOCK) - return proc_mutex_spinsleep_timedacquire(mutex, timeout, absolute); + return proc_mutex_spinsleep_timedacquire(mutex, timeout); #else apr_status_t rv; @@ -754,11 +745,11 @@ static apr_status_t proc_mutex_pthread_timedacquire(apr_proc_mutex_t *mutex, } else { struct timespec abstime; - if (!absolute) { - timeout += apr_time_now(); - } + + timeout += apr_time_now(); abstime.tv_sec = apr_time_sec(timeout); abstime.tv_nsec = apr_time_usec(timeout) * 1000; /* nanoseconds */ + rv = pthread_cond_timedwait(&proc_pthread_mutex_cond(mutex), &proc_pthread_mutex(mutex), &abstime); @@ -810,11 +801,11 @@ static apr_status_t proc_mutex_pthread_timedacquire(apr_proc_mutex_t *mutex, } else { struct timespec abstime; - if (!absolute) { - timeout += apr_time_now(); - } + + timeout += apr_time_now(); abstime.tv_sec = apr_time_sec(timeout); abstime.tv_nsec = apr_time_usec(timeout) * 1000; /* nanoseconds */ + rv = pthread_mutex_timedlock(&proc_pthread_mutex(mutex), &abstime); if (rv) { #ifdef HAVE_ZOS_PTHREADS @@ -1564,10 +1555,9 @@ APR_DECLARE(apr_status_t) apr_proc_mutex_trylock(apr_proc_mutex_t *mutex) } APR_DECLARE(apr_status_t) apr_proc_mutex_timedlock(apr_proc_mutex_t *mutex, - apr_time_t timeout, - int absolute) + apr_time_t timeout) { - return mutex->meth->timedacquire(mutex, timeout, absolute); + return mutex->meth->timedacquire(mutex, timeout); } APR_DECLARE(apr_status_t) apr_proc_mutex_unlock(apr_proc_mutex_t *mutex) diff --git a/locks/unix/thread_mutex.c b/locks/unix/thread_mutex.c index fe515b2e6..be2d86586 100644 --- a/locks/unix/thread_mutex.c +++ b/locks/unix/thread_mutex.c @@ -190,26 +190,34 @@ APR_DECLARE(apr_status_t) apr_thread_mutex_trylock(apr_thread_mutex_t *mutex) } APR_DECLARE(apr_status_t) apr_thread_mutex_timedlock(apr_thread_mutex_t *mutex, - apr_time_t timeout, - int absolute) + apr_time_t timeout) { apr_status_t rv = APR_ENOTIMPL; #ifdef HAVE_PTHREAD_MUTEX_TIMEDLOCK if (timeout < 0) { rv = pthread_mutex_lock(&mutex->mutex); +#ifdef HAVE_ZOS_PTHREADS + if (rv) { + rv = errno; + } +#endif + } + else if (!timeout) { + rv = pthread_mutex_trylock(&mutex->mutex); if (rv) { #ifdef HAVE_ZOS_PTHREADS rv = errno; #endif + if (rv == EBUSY) { + rv = APR_TIMEUP; + } } } else { struct timespec abstime; - if (!absolute) { - timeout += apr_time_now(); - } + timeout += apr_time_now(); abstime.tv_sec = apr_time_sec(timeout); abstime.tv_nsec = apr_time_usec(timeout) * 1000; /* nanoseconds */ @@ -227,8 +235,6 @@ APR_DECLARE(apr_status_t) apr_thread_mutex_timedlock(apr_thread_mutex_t *mutex, #else /* HAVE_PTHREAD_MUTEX_TIMEDLOCK */ if (mutex->cond) { - apr_status_t rv2; - rv = pthread_mutex_lock(&mutex->mutex); if (rv) { #ifdef HAVE_ZOS_PTHREADS @@ -238,35 +244,40 @@ APR_DECLARE(apr_status_t) apr_thread_mutex_timedlock(apr_thread_mutex_t *mutex, } if (mutex->locked) { - mutex->num_waiters++; - if (timeout < 0) { - rv = apr_thread_cond_wait(mutex->cond, mutex); + if (!timeout) { + rv = APR_TIMEUP; } else { - if (absolute) { - apr_time_t now = apr_time_now(); - if (timeout > now) { - timeout -= now; - } - else { - timeout = 0; - } + mutex->num_waiters++; + if (timeout < 0) { + rv = apr_thread_cond_wait(mutex->cond, mutex); + } + else { + rv = apr_thread_cond_timedwait(mutex->cond, mutex, + timeout); } - rv = apr_thread_cond_timedwait(mutex->cond, mutex, timeout); +#ifdef HAVE_ZOS_PTHREADS + if (rv) { + rv = errno; + } +#endif + mutex->num_waiters--; } - mutex->num_waiters--; } else { mutex->locked = 1; } + if (rv) { + pthread_mutex_unlock(&mutex->mutex); + return rv; + } - rv2 = pthread_mutex_unlock(&mutex->mutex); - if (rv2 && !rv) { + rv = pthread_mutex_unlock(&mutex->mutex); + if (rv) { #ifdef HAVE_ZOS_PTHREADS rv = errno; -#else - rv = rv2; #endif + return rv; } } diff --git a/locks/win32/proc_mutex.c b/locks/win32/proc_mutex.c index b51f856c0..7c3df23dc 100644 --- a/locks/win32/proc_mutex.c +++ b/locks/win32/proc_mutex.c @@ -165,8 +165,7 @@ APR_DECLARE(apr_status_t) apr_proc_mutex_trylock(apr_proc_mutex_t *mutex) } APR_DECLARE(apr_status_t) apr_proc_mutex_timedlock(apr_proc_mutex_t *mutex, - apr_time_t timeout, - int absolute) + apr_time_t timeout) { DWORD rv; @@ -174,15 +173,6 @@ APR_DECLARE(apr_status_t) apr_proc_mutex_timedlock(apr_proc_mutex_t *mutex, rv = WaitForSingleObject(mutex->handle, INFINITE); } else { - if (absolute) { - apr_time_t now = apr_time_now(); - if (timeout > now) { - timeout -= now; - } - else { - timeout = 0; - } - } rv = WaitForSingleObject(mutex->handle, apr_time_as_msec(timeout)); if (rv == WAIT_TIMEOUT) { return APR_TIMEUP; diff --git a/locks/win32/thread_mutex.c b/locks/win32/thread_mutex.c index cd0ccf5ba..05dc3d5fb 100644 --- a/locks/win32/thread_mutex.c +++ b/locks/win32/thread_mutex.c @@ -115,8 +115,7 @@ APR_DECLARE(apr_status_t) apr_thread_mutex_trylock(apr_thread_mutex_t *mutex) } APR_DECLARE(apr_status_t) apr_thread_mutex_timedlock(apr_thread_mutex_t *mutex, - apr_time_t timeout, - int absolute) + apr_time_t timeout) { if (mutex->type != thread_mutex_critical_section) { DWORD rv, timeout_ms; @@ -124,15 +123,6 @@ APR_DECLARE(apr_status_t) apr_thread_mutex_timedlock(apr_thread_mutex_t *mutex, timeout_ms = INFINITE; } else { - if (absolute) { - apr_time_t now = apr_time_now(); - if (timeout > now) { - timeout -= now; - } - else { - timeout = 0; - } - } timeout_ms = apr_time_as_msec(timeout); } rv = WaitForSingleObject(mutex->handle, timeout_ms); diff --git a/test/testlock.c b/test/testlock.c index 45eddb02e..095134e05 100644 --- a/test/testlock.c +++ b/test/testlock.c @@ -91,7 +91,7 @@ static void *APR_THREAD_FUNC thread_mutex_function(apr_thread_t *thd, void *data while (1) { if (data) { - apr_thread_mutex_timedlock(thread_mutex, *(apr_time_t *)data, 0); + apr_thread_mutex_timedlock(thread_mutex, *(apr_time_t *)data); } else { apr_thread_mutex_lock(thread_mutex); @@ -358,7 +358,7 @@ static void test_timeoutmutex(abts_case *tc, void *data) ABTS_INT_EQUAL(tc, 0, apr_thread_mutex_lock(timeout_mutex)); for (i = 0; i < MAX_RETRY; i++) { begin = apr_time_now(); - s = apr_thread_mutex_timedlock(timeout_mutex, timeout, 0); + s = apr_thread_mutex_timedlock(timeout_mutex, timeout); end = apr_time_now(); if (s != APR_SUCCESS && !APR_STATUS_IS_TIMEUP(s)) { diff --git a/test/testlockperf.c b/test/testlockperf.c index 10442710d..c91f1a87b 100644 --- a/test/testlockperf.c +++ b/test/testlockperf.c @@ -61,7 +61,7 @@ void * APR_THREAD_FUNC thread_mutex_func(apr_thread_t *thd, void *data) for (i = 0; i < max_counter; i++) { if (data) { - apr_thread_mutex_timedlock(thread_lock, *(apr_time_t *)data, 0); + apr_thread_mutex_timedlock(thread_lock, *(apr_time_t *)data); } else { apr_thread_mutex_lock(thread_lock); diff --git a/test/testprocmutex.c b/test/testprocmutex.c index 3aff25b88..983aa953a 100644 --- a/test/testprocmutex.c +++ b/test/testprocmutex.c @@ -88,7 +88,7 @@ static void make_child(abts_case *tc, int trylock, apr_proc_t **proc, apr_pool_t else if (trylock < 0) { int wait_usec = 0; - while ((rv = apr_proc_mutex_timedlock(proc_lock, 1, 0))) { + while ((rv = apr_proc_mutex_timedlock(proc_lock, 1))) { if (!APR_STATUS_IS_TIMEUP(rv)) exit(1); if (++wait_usec >= MAX_WAIT_USEC) @@ -184,7 +184,7 @@ static void test_exclusive(abts_case *tc, const char *lockname, *x == MAX_COUNTER); } - rv = apr_proc_mutex_timedlock(proc_lock, 1, 0); + rv = apr_proc_mutex_timedlock(proc_lock, 1); if (rv == APR_ENOTIMPL) { fprintf(stderr, "%s_timedlock() not implemented, ", mech->name); ABTS_ASSERT(tc, "Default timed timedlock not implemented", @@ -194,7 +194,7 @@ static void test_exclusive(abts_case *tc, const char *lockname, APR_ASSERT_SUCCESS(tc, "check for timedlock", rv); for (n = 0; n < 2; n++) { - rv = apr_proc_mutex_timedlock(proc_lock, 1, 0); + rv = apr_proc_mutex_timedlock(proc_lock, 1); /* Some mech (eg. flock or fcntl) may succeed when the * lock is re-acquired in the same process. */ |