summaryrefslogtreecommitdiff
path: root/locks
diff options
context:
space:
mode:
authorYann Ylavic <ylavic@apache.org>2019-03-22 01:27:18 +0000
committerYann Ylavic <ylavic@apache.org>2019-03-22 01:27:18 +0000
commit4b0365c31858da04108dcc33ff514d898d20b9ad (patch)
tree5c1f096f453ec077fb86a2325439fefdb821c5c1 /locks
parenta05bc5213c1ac82e85c0167d158548436bd5a6c9 (diff)
downloadapr-4b0365c31858da04108dcc33ff514d898d20b9ad.tar.gz
Use proc mutex pthread by default when robust[_np]
On platforms that support pshared and robust pthread mutex, this is usually the best interprocess mutex mechanism because it's efficient, posix, not limited and not persistent on the system when the program exits (i.e. no need to delete it explicitely before leaving, like IPC SysV or files for instance). Note that on older POSIX systems pthread_mutex_{setrobust,consistent}() funcs existed with the non-posix _np() suffix, and we consider them equivalent. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1856022 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'locks')
-rw-r--r--locks/unix/proc_mutex.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/locks/unix/proc_mutex.c b/locks/unix/proc_mutex.c
index a8002c6bd..649c6f00e 100644
--- a/locks/unix/proc_mutex.c
+++ b/locks/unix/proc_mutex.c
@@ -619,9 +619,13 @@ static apr_status_t proc_mutex_pthread_create(apr_proc_mutex_t *new_mutex,
return rv;
}
+#if defined(HAVE_PTHREAD_MUTEX_ROBUST) || defined(HAVE_PTHREAD_MUTEX_ROBUST_NP)
#ifdef HAVE_PTHREAD_MUTEX_ROBUST
- if ((rv = pthread_mutexattr_setrobust_np(&mattr,
- PTHREAD_MUTEX_ROBUST_NP))) {
+ rv = pthread_mutexattr_setrobust(&mattr, PTHREAD_MUTEX_ROBUST);
+#else
+ rv = pthread_mutexattr_setrobust_np(&mattr, PTHREAD_MUTEX_ROBUST_NP);
+#endif
+ if (rv) {
#ifdef HAVE_ZOS_PTHREADS
rv = errno;
#endif
@@ -637,7 +641,7 @@ static apr_status_t proc_mutex_pthread_create(apr_proc_mutex_t *new_mutex,
pthread_mutexattr_destroy(&mattr);
return rv;
}
-#endif /* HAVE_PTHREAD_MUTEX_ROBUST */
+#endif /* HAVE_PTHREAD_MUTEX_ROBUST[_NP] */
if ((rv = pthread_mutex_init(&proc_pthread_mutex(new_mutex), &mattr))) {
#ifdef HAVE_ZOS_PTHREADS
@@ -689,11 +693,15 @@ static apr_status_t proc_mutex_pthread_acquire_ex(apr_proc_mutex_t *mutex,
#ifdef HAVE_ZOS_PTHREADS
rv = errno;
#endif
-#ifdef HAVE_PTHREAD_MUTEX_ROBUST
+#if defined(HAVE_PTHREAD_MUTEX_ROBUST) || defined(HAVE_PTHREAD_MUTEX_ROBUST_NP)
/* Okay, our owner died. Let's try to make it consistent again. */
if (rv == EOWNERDEAD) {
proc_pthread_mutex_dec(mutex);
+#ifdef HAVE_PTHREAD_MUTEX_ROBUST
+ pthread_mutex_consistent(&proc_pthread_mutex(mutex));
+#else
pthread_mutex_consistent_np(&proc_pthread_mutex(mutex));
+#endif
}
else
#endif
@@ -801,11 +809,15 @@ static apr_status_t proc_mutex_pthread_acquire_ex(apr_proc_mutex_t *mutex,
}
}
if (rv) {
-#ifdef HAVE_PTHREAD_MUTEX_ROBUST
+#if defined(HAVE_PTHREAD_MUTEX_ROBUST) || defined(HAVE_PTHREAD_MUTEX_ROBUST_NP)
/* Okay, our owner died. Let's try to make it consistent again. */
if (rv == EOWNERDEAD) {
proc_pthread_mutex_dec(mutex);
+#ifdef HAVE_PTHREAD_MUTEX_ROBUST
+ pthread_mutex_consistent(&proc_pthread_mutex(mutex));
+#else
pthread_mutex_consistent_np(&proc_pthread_mutex(mutex));
+#endif
}
else
#endif
@@ -847,11 +859,15 @@ static apr_status_t proc_mutex_pthread_release(apr_proc_mutex_t *mutex)
#ifdef HAVE_ZOS_PTHREADS
rv = errno;
#endif
-#ifdef HAVE_PTHREAD_MUTEX_ROBUST
+#if defined(HAVE_PTHREAD_MUTEX_ROBUST) || defined(HAVE_PTHREAD_MUTEX_ROBUST_NP)
/* Okay, our owner died. Let's try to make it consistent again. */
if (rv == EOWNERDEAD) {
proc_pthread_mutex_dec(mutex);
+#ifdef HAVE_PTHREAD_MUTEX_ROBUST
+ pthread_mutex_consistent(&proc_pthread_mutex(mutex));
+#else
pthread_mutex_consistent_np(&proc_pthread_mutex(mutex));
+#endif
}
else
#endif