You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by wr...@apache.org on 2017/05/23 19:20:39 UTC
svn commit: r1795952 - in /apr/apr/branches/1.6.x: locks/unix/misc.c
locks/unix/proc_mutex.c locks/unix/thread_mutex.c test/testlock.c
Author: wrowe
Date: Tue May 23 19:20:38 2017
New Revision: 1795952
URL: http://svn.apache.org/viewvc?rev=1795952&view=rev
Log:
Revert r1790105;
Add in our own pthread_mutex_timedlock impl for those OSs, like
osx/macos that don't have it. Be a bit more generous in the test
Removed:
apr/apr/branches/1.6.x/locks/unix/misc.c
Modified:
apr/apr/branches/1.6.x/locks/unix/proc_mutex.c
apr/apr/branches/1.6.x/locks/unix/thread_mutex.c
apr/apr/branches/1.6.x/test/testlock.c
Modified: apr/apr/branches/1.6.x/locks/unix/proc_mutex.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.6.x/locks/unix/proc_mutex.c?rev=1795952&r1=1795951&r2=1795952&view=diff
==============================================================================
--- apr/apr/branches/1.6.x/locks/unix/proc_mutex.c (original)
+++ apr/apr/branches/1.6.x/locks/unix/proc_mutex.c Tue May 23 19:20:38 2017
@@ -654,9 +654,7 @@ static apr_status_t proc_mutex_pthread_t
apr_time_t timeout,
int absolute)
{
-#ifndef HAVE_PTHREAD_MUTEX_TIMEDLOCK
-extern int pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *abs_timeout);
-#endif
+#ifdef HAVE_PTHREAD_MUTEX_TIMEDLOCK
if (timeout < 0) {
return proc_mutex_pthread_acquire(mutex);
}
@@ -691,6 +689,9 @@ extern int pthread_mutex_timedlock(pthre
}
mutex->curr_locked = 1;
return APR_SUCCESS;
+#else
+ return APR_ENOTIMPL;
+#endif
}
static apr_status_t proc_mutex_pthread_release(apr_proc_mutex_t *mutex)
@@ -1219,7 +1220,8 @@ static apr_status_t proc_mutex_choose_me
break;
case APR_LOCK_DEFAULT_TIMED:
#if APR_HAS_PROC_PTHREAD_SERIALIZE \
- && defined(HAVE_PTHREAD_MUTEX_ROBUST)
+ && defined(HAVE_PTHREAD_MUTEX_ROBUST) \
+ && defined(HAVE_PTHREAD_MUTEX_TIMEDLOCK)
new_mutex->meth = &mutex_proc_pthread_methods;
#elif APR_HAS_SYSVSEM_SERIALIZE \
&& defined(HAVE_SEMTIMEDOP)
Modified: apr/apr/branches/1.6.x/locks/unix/thread_mutex.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.6.x/locks/unix/thread_mutex.c?rev=1795952&r1=1795951&r2=1795952&view=diff
==============================================================================
--- apr/apr/branches/1.6.x/locks/unix/thread_mutex.c (original)
+++ apr/apr/branches/1.6.x/locks/unix/thread_mutex.c Tue May 23 19:20:38 2017
@@ -77,6 +77,19 @@ APR_DECLARE(apr_status_t) apr_thread_mut
return rv;
}
+#ifndef HAVE_PTHREAD_MUTEX_TIMEDLOCK
+ if (flags & APR_THREAD_MUTEX_TIMED) {
+ rv = apr_thread_cond_create(&new_mutex->cond, pool);
+ if (rv) {
+#ifdef HAVE_ZOS_PTHREADS
+ rv = errno;
+#endif
+ pthread_mutex_destroy(&new_mutex->mutex);
+ return rv;
+ }
+ }
+#endif
+
apr_pool_cleanup_register(new_mutex->pool,
new_mutex, thread_mutex_cleanup,
apr_pool_cleanup_null);
@@ -182,10 +195,7 @@ APR_DECLARE(apr_status_t) apr_thread_mut
{
apr_status_t rv = APR_ENOTIMPL;
-#ifndef HAVE_PTHREAD_MUTEX_TIMEDLOCK
-extern int pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *abs_timeout);
-#endif
-
+#ifdef HAVE_PTHREAD_MUTEX_TIMEDLOCK
if (timeout < 0) {
rv = pthread_mutex_lock(&mutex->mutex);
if (rv) {
@@ -213,6 +223,55 @@ extern int pthread_mutex_timedlock(pthre
}
}
}
+
+#else /* HAVE_PTHREAD_MUTEX_TIMEDLOCK */
+
+ if (mutex->cond) {
+ apr_status_t rv2;
+
+ rv = pthread_mutex_lock(&mutex->mutex);
+ if (rv) {
+#ifdef HAVE_ZOS_PTHREADS
+ rv = errno;
+#endif
+ return rv;
+ }
+
+ if (mutex->locked) {
+ mutex->num_waiters++;
+ if (timeout < 0) {
+ rv = apr_thread_cond_wait(mutex->cond, mutex);
+ }
+ else {
+ if (absolute) {
+ apr_time_t now = apr_time_now();
+ if (timeout > now) {
+ timeout -= now;
+ }
+ else {
+ timeout = 0;
+ }
+ }
+ rv = apr_thread_cond_timedwait(mutex->cond, mutex, timeout);
+ }
+ mutex->num_waiters--;
+ }
+ else {
+ mutex->locked = 1;
+ }
+
+ rv2 = pthread_mutex_unlock(&mutex->mutex);
+ if (rv2 && !rv) {
+#ifdef HAVE_ZOS_PTHREADS
+ rv = errno;
+#else
+ rv = rv2;
+#endif
+ }
+ }
+
+#endif /* HAVE_PTHREAD_MUTEX_TIMEDLOCK */
+
return rv;
}
Modified: apr/apr/branches/1.6.x/test/testlock.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.6.x/test/testlock.c?rev=1795952&r1=1795951&r2=1795952&view=diff
==============================================================================
--- apr/apr/branches/1.6.x/test/testlock.c (original)
+++ apr/apr/branches/1.6.x/test/testlock.c Tue May 23 19:20:38 2017
@@ -368,7 +368,7 @@ static void test_timeoutmutex(abts_case
continue;
}
ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_TIMEUP(s));
- ABTS_ASSERT(tc, "Timer returned too late", end - begin - timeout < 1000000);
+ ABTS_ASSERT(tc, "Timer returned too late", end - begin - timeout < 100000);
break;
}
ABTS_ASSERT(tc, "Too many retries", i < MAX_RETRY);