From 4b0365c31858da04108dcc33ff514d898d20b9ad Mon Sep 17 00:00:00 2001 From: Yann Ylavic Date: Fri, 22 Mar 2019 01:27:18 +0000 Subject: 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 --- locks/unix/proc_mutex.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'locks') 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 -- cgit v1.2.1