diff options
Diffstat (limited to 'locks/unix')
-rw-r--r-- | locks/unix/thread_mutex.c | 44 |
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); |