summaryrefslogtreecommitdiff
path: root/locks/unix
diff options
context:
space:
mode:
authorylavic <ylavic@13f79535-47bb-0310-9956-ffa450edef68>2017-05-07 21:35:30 +0000
committerylavic <ylavic@13f79535-47bb-0310-9956-ffa450edef68>2017-05-07 21:35:30 +0000
commit2a38adcde87a3fe074e5e998cb2e658d5084ce81 (patch)
tree278e91fb321da52936150a853c31c111aec4d7bb /locks/unix
parentc67f389a1051f39afde0f194bf0d49e430f7c6fc (diff)
downloadlibapr-2a38adcde87a3fe074e5e998cb2e658d5084ce81.tar.gz
locks: thread: timedlock: better handling of spurious wakeups that may be
inherent to some native/OS condvar implementation. git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@1794266 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'locks/unix')
-rw-r--r--locks/unix/thread_mutex.c44
1 files changed, 18 insertions, 26 deletions
diff --git a/locks/unix/thread_mutex.c b/locks/unix/thread_mutex.c
index cf859e6ad..f027c791f 100644
--- a/locks/unix/thread_mutex.c
+++ b/locks/unix/thread_mutex.c
@@ -241,23 +241,26 @@ APR_DECLARE(apr_status_t) apr_thread_mutex_timedlock(apr_thread_mutex_t *mutex,
}
else {
mutex->num_waiters++;
- rv = apr_thread_cond_timedwait(mutex->cond, mutex, timeout);
+ do {
+ rv = apr_thread_cond_timedwait(mutex->cond, mutex,
+ timeout);
+ if (rv) {
#ifdef HAVE_ZOS_PTHREADS
- if (rv) {
- rv = errno;
- }
+ rv = errno;
#endif
+ break;
+ }
+ } while (mutex->locked);
mutex->num_waiters--;
}
- }
- else {
- mutex->locked = 1;
- }
- if (rv) {
- pthread_mutex_unlock(&mutex->mutex);
- return rv;
+ if (rv) {
+ pthread_mutex_unlock(&mutex->mutex);
+ return rv;
+ }
}
+ mutex->locked = 1;
+
rv = pthread_mutex_unlock(&mutex->mutex);
if (rv) {
#ifdef HAVE_ZOS_PTHREADS
@@ -277,8 +280,6 @@ APR_DECLARE(apr_status_t) apr_thread_mutex_unlock(apr_thread_mutex_t *mutex)
apr_status_t status;
if (mutex->cond) {
- apr_status_t stat2;
-
status = pthread_mutex_lock(&mutex->mutex);
if (status) {
#ifdef HAVE_ZOS_PTHREADS
@@ -293,21 +294,12 @@ APR_DECLARE(apr_status_t) apr_thread_mutex_unlock(apr_thread_mutex_t *mutex)
else if (mutex->num_waiters) {
status = apr_thread_cond_signal(mutex->cond);
}
- else {
- mutex->locked = 0;
- status = APR_SUCCESS;
- }
-
- stat2 = pthread_mutex_unlock(&mutex->mutex);
- if (stat2) {
-#ifdef HAVE_ZOS_PTHREADS
- status = errno;
-#else
- status = stat2;
-#endif
+ if (status) {
+ pthread_mutex_unlock(&mutex->mutex);
+ return status;
}
- return status;
+ mutex->locked = 0;
}
status = pthread_mutex_unlock(&mutex->mutex);