diff options
author | Yann Ylavic <ylavic@apache.org> | 2019-03-22 01:27:18 +0000 |
---|---|---|
committer | Yann Ylavic <ylavic@apache.org> | 2019-03-22 01:27:18 +0000 |
commit | 4b0365c31858da04108dcc33ff514d898d20b9ad (patch) | |
tree | 5c1f096f453ec077fb86a2325439fefdb821c5c1 /build | |
parent | a05bc5213c1ac82e85c0167d158548436bd5a6c9 (diff) | |
download | apr-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 'build')
-rw-r--r-- | build/apr_threads.m4 | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/build/apr_threads.m4 b/build/apr_threads.m4 index cbc677b14..6895c3a67 100644 --- a/build/apr_threads.m4 +++ b/build/apr_threads.m4 @@ -262,6 +262,33 @@ int main(int argc, char **argv) exit(1); if (pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED)) exit(2); + if (pthread_mutexattr_setrobust(&attr, PTHREAD_MUTEX_ROBUST)) + exit(3); + if (pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT)) + exit(4); + if (pthread_mutex_init(&mutex, &attr)) + exit(5); + if (pthread_mutexattr_destroy(&attr)) + exit(6); + if (pthread_mutex_destroy(&mutex)) + exit(7); + + exit(0); +}], [apr_cv_mutex_robust_shared=yes], [ +AC_TRY_RUN([ +#include <sys/types.h> +#include <pthread.h> +#include <stdlib.h> + +int main(int argc, char **argv) +{ + pthread_mutex_t mutex; + pthread_mutexattr_t attr; + + if (pthread_mutexattr_init(&attr)) + exit(1); + if (pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED)) + exit(2); if (pthread_mutexattr_setrobust_np(&attr, PTHREAD_MUTEX_ROBUST_NP)) exit(3); if (pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT)) @@ -274,10 +301,14 @@ int main(int argc, char **argv) exit(7); exit(0); -}], [apr_cv_mutex_robust_shared=yes], [apr_cv_mutex_robust_shared=no])]) +}], [apr_cv_mutex_robust_shared=np], [apr_cv_mutex_robust_shared=no]) +])]) if test "$apr_cv_mutex_robust_shared" = "yes"; then AC_DEFINE([HAVE_PTHREAD_MUTEX_ROBUST], 1, [Define if cross-process robust mutexes are available]) +elif test "$apr_cv_mutex_robust_shared" = "np"; then + AC_DEFINE([HAVE_PTHREAD_MUTEX_ROBUST_NP], 1, + [Define if non-posix/portable cross-process robust mutexes are available]) fi ]) |