diff options
author | Yann Ylavic <ylavic@apache.org> | 2015-03-20 09:16:56 +0000 |
---|---|---|
committer | Yann Ylavic <ylavic@apache.org> | 2015-03-20 09:16:56 +0000 |
commit | cdfe10ee837e20862e90ee7c049c5bde67f69891 (patch) | |
tree | 028abc1c6ee07d940fcc83ba3726511c5195595b /locks/beos | |
parent | 5efe443673d85ba5e94edbbb4383d9a968f56b94 (diff) | |
download | apr-cdfe10ee837e20862e90ee7c049c5bde67f69891.tar.gz |
Follow up to r1667900: handle negative (infinite) timeout in mutex/cond timedlock/timedwait.
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1667962 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'locks/beos')
-rw-r--r-- | locks/beos/proc_mutex.c | 37 | ||||
-rw-r--r-- | locks/beos/thread_mutex.c | 40 |
2 files changed, 41 insertions, 36 deletions
diff --git a/locks/beos/proc_mutex.c b/locks/beos/proc_mutex.c index 0283040bb..4408df094 100644 --- a/locks/beos/proc_mutex.c +++ b/locks/beos/proc_mutex.c @@ -115,27 +115,28 @@ APR_DECLARE(apr_status_t) apr_proc_mutex_timedlock(apr_proc_mutex_t *mutex, int32 stat; if (atomic_add(&mutex->LockCount, 1) > 0) { - int flag = 0; -#ifdef B_ABSOLUTE_TIMEOUT - if (timeout) { - flag = absolute ? B_ABSOLUTE_TIMEOUT : B_RELATIVE_TIMEOUT; + if (timeout < 0) { + stat = acquire_sem(mutex->Lock); } - stat = acquire_sem_etc(mutex->Lock, 1, flag, timeout); -#else - if (absolute) { - apr_time_t now = apr_time_now(); - if (timeout > now) { - timeout -= now; + 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; + } } - else { - timeout = 0; - } - } - if (timeout) { - flag = B_RELATIVE_TIMEOUT; + stat = acquire_sem_etc(mutex->Lock, 1, flag, timeout); } - stat = acquire_sem_etc(mutex->Lock, 1, flag, timeout); -#endif if (stat < B_NO_ERROR) { atomic_add(&mutex->LockCount, -1); if (stat == B_TIMED_OUT) { diff --git a/locks/beos/thread_mutex.c b/locks/beos/thread_mutex.c index 257d12508..2fa1bc70b 100644 --- a/locks/beos/thread_mutex.c +++ b/locks/beos/thread_mutex.c @@ -116,8 +116,7 @@ APR_DECLARE(apr_status_t) apr_thread_mutex_trylock(apr_thread_mutex_t *mutex) } if (atomic_add(&mutex->LockCount, 1) > 0) { - if ((stat = acquire_sem_etc(mutex->Lock, 1, - B_TIMEOUT, 0)) < B_NO_ERROR) { + if ((stat = acquire_sem_etc(mutex->Lock, 1, 0, 0)) < B_NO_ERROR) { atomic_add(&mutex->LockCount, -1); if (stat == B_WOULD_BLOCK) { stat = APR_EBUSY; @@ -145,24 +144,29 @@ APR_DECLARE(apr_status_t) apr_thread_mutex_timedlock(apr_thread_mutex_t *mutex, } if (atomic_add(&mutex->LockCount, 1) > 0) { -#ifdef B_ABSOLUTE_TIMEOUT - stat = acquire_sem_etc(mutex->Lock, 1, - absolute ? B_ABSOLUTE_TIMEOUT - : B_RELATIVE_TIMEOUT, - timeout); -#else - if (absolute) { - apr_time_t now = apr_time_now(); - if (timeout > now) { - timeout -= now; - } - else { - timeout = 0; + 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_TIMEOUT, timeout); -#endif - if (stat < B_NO_ERROR) { + if (stat < B_NO_ERROR) { atomic_add(&mutex->LockCount, -1); if (stat == B_TIMED_OUT) { stat = APR_TIMEUP; |