diff options
author | wrowe <wrowe@13f79535-47bb-0310-9956-ffa450edef68> | 2017-05-23 16:33:48 +0000 |
---|---|---|
committer | wrowe <wrowe@13f79535-47bb-0310-9956-ffa450edef68> | 2017-05-23 16:33:48 +0000 |
commit | 7d5011ced29692e05306de02f7ca819cb399d396 (patch) | |
tree | 526fa3f8dc5f8e16e52047857f4eb24c67afe6f0 | |
parent | be70ed04c10c3906355b4a94ddaea61be43ff122 (diff) | |
download | libapr-7d5011ced29692e05306de02f7ca819cb399d396.tar.gz |
Revert r1794259 (r1792621, r1792622, r1792625 from trunk)
locks: unix: provide a macro helper for a pattern used several times.
No functional change.
locks: unix: timedlock: better handling of spurious wakeups that may be
inherent to some native/OS condvar implementation.
locks: unix: follow up to r1792622.
Indent block previously preserved (for easier review), no functional change.
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/branches/1.6.x@1795933 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | locks/unix/proc_mutex.c | 83 |
1 files changed, 38 insertions, 45 deletions
diff --git a/locks/unix/proc_mutex.c b/locks/unix/proc_mutex.c index 863b07ab6..3708b8eb0 100644 --- a/locks/unix/proc_mutex.c +++ b/locks/unix/proc_mutex.c @@ -497,8 +497,6 @@ typedef struct { apr_uint32_t cond_num_waiters; #define proc_pthread_mutex_cond_num_waiters(m) \ (proc_pthread_cast(m)->cond_num_waiters) -#define proc_pthread_mutex_is_cond(m) \ - ((m)->pthread_refcounting && proc_pthread_mutex_cond_locked(m) != -1) #endif /* APR_USE_PROC_PTHREAD_MUTEX_COND */ apr_uint32_t refcount; #define proc_pthread_mutex_refcount(m) \ @@ -529,7 +527,8 @@ static apr_status_t proc_pthread_mutex_unref(void *mutex_) apr_status_t rv; #if APR_USE_PROC_PTHREAD_MUTEX_COND - if (proc_pthread_mutex_is_cond(mutex)) { + if (mutex->pthread_refcounting && + proc_pthread_mutex_cond_locked(mutex) != -1) { mutex->curr_locked = 0; } else @@ -544,7 +543,8 @@ static apr_status_t proc_pthread_mutex_unref(void *mutex_) } if (!proc_pthread_mutex_dec(mutex)) { #if APR_USE_PROC_PTHREAD_MUTEX_COND - if (proc_pthread_mutex_is_cond(mutex) && + if (mutex->pthread_refcounting && + proc_pthread_mutex_cond_locked(mutex) != -1 && (rv = pthread_cond_destroy(&proc_pthread_mutex_cond(mutex)))) { #ifdef HAVE_ZOS_PTHREADS rv = errno; @@ -690,7 +690,8 @@ static apr_status_t proc_mutex_pthread_acquire_ex(apr_proc_mutex_t *mutex, apr_status_t rv; #if APR_USE_PROC_PTHREAD_MUTEX_COND - if (proc_pthread_mutex_is_cond(mutex)) { + if (mutex->pthread_refcounting && + proc_pthread_mutex_cond_locked(mutex) != -1) { if ((rv = pthread_mutex_lock(&proc_pthread_mutex(mutex)))) { #ifdef HAVE_ZOS_PTHREADS rv = errno; @@ -707,56 +708,48 @@ static apr_status_t proc_mutex_pthread_acquire_ex(apr_proc_mutex_t *mutex, } if (!proc_pthread_mutex_cond_locked(mutex)) { - rv = APR_SUCCESS; + proc_pthread_mutex_cond_locked(mutex) = 1; } else if (!timeout) { rv = APR_TIMEUP; } else { - struct timespec abstime; + proc_pthread_mutex_cond_num_waiters(mutex)++; + if (timeout < 0) { + rv = pthread_cond_wait(&proc_pthread_mutex_cond(mutex), + &proc_pthread_mutex(mutex)); +#ifdef HAVE_ZOS_PTHREADS + if (rv) { + rv = errno; + } +#endif + } + else { + struct timespec abstime; - if (timeout > 0) { timeout += apr_time_now(); abstime.tv_sec = apr_time_sec(timeout); abstime.tv_nsec = apr_time_usec(timeout) * 1000; /* nanoseconds */ - } - proc_pthread_mutex_cond_num_waiters(mutex)++; - do { - if (timeout < 0) { - rv = pthread_cond_wait(&proc_pthread_mutex_cond(mutex), - &proc_pthread_mutex(mutex)); - if (rv) { + rv = pthread_cond_timedwait(&proc_pthread_mutex_cond(mutex), + &proc_pthread_mutex(mutex), + &abstime); + if (rv) { #ifdef HAVE_ZOS_PTHREADS - rv = errno; + rv = errno; #endif - break; + if (rv == ETIMEDOUT) { + rv = APR_TIMEUP; } } - else { - rv = pthread_cond_timedwait(&proc_pthread_mutex_cond(mutex), - &proc_pthread_mutex(mutex), - &abstime); - if (rv) { -#ifdef HAVE_ZOS_PTHREADS - rv = errno; -#endif - if (rv == ETIMEDOUT) { - rv = APR_TIMEUP; - } - break; - } - } - } while (proc_pthread_mutex_cond_locked(mutex)); + } proc_pthread_mutex_cond_num_waiters(mutex)--; } - if (rv != APR_SUCCESS) { + if (rv) { pthread_mutex_unlock(&proc_pthread_mutex(mutex)); return rv; } - proc_pthread_mutex_cond_locked(mutex) = 1; - rv = pthread_mutex_unlock(&proc_pthread_mutex(mutex)); if (rv) { #ifdef HAVE_ZOS_PTHREADS @@ -848,7 +841,8 @@ static apr_status_t proc_mutex_pthread_release(apr_proc_mutex_t *mutex) apr_status_t rv; #if APR_USE_PROC_PTHREAD_MUTEX_COND - if (proc_pthread_mutex_is_cond(mutex)) { + if (mutex->pthread_refcounting && + proc_pthread_mutex_cond_locked(mutex) != -1) { if ((rv = pthread_mutex_lock(&proc_pthread_mutex(mutex)))) { #ifdef HAVE_ZOS_PTHREADS rv = errno; @@ -867,23 +861,22 @@ static apr_status_t proc_mutex_pthread_release(apr_proc_mutex_t *mutex) if (!proc_pthread_mutex_cond_locked(mutex)) { rv = APR_EINVAL; } - else if (!proc_pthread_mutex_cond_num_waiters(mutex)) { - rv = APR_SUCCESS; - } - else { + else if (proc_pthread_mutex_cond_num_waiters(mutex)) { rv = pthread_cond_signal(&proc_pthread_mutex_cond(mutex)); -#ifdef HAVE_ZOS_PTHREADS if (rv) { +#ifdef HAVE_ZOS_PTHREADS rv = errno; - } #endif + } } - if (rv != APR_SUCCESS) { + else { + proc_pthread_mutex_cond_locked(mutex) = 0; + rv = APR_SUCCESS; + } + if (rv) { pthread_mutex_unlock(&proc_pthread_mutex(mutex)); return rv; } - - proc_pthread_mutex_cond_locked(mutex) = 0; } #endif /* APR_USE_PROC_PTHREAD_MUTEX_COND */ |