>From aa8aa5d8866366c06d3f06d9ac1cf8cd3614cf88 Mon Sep 17 00:00:00 2001 From: Bruno Haible Subject: [PATCH 1/5] pthread-mutex: Fix errors in C++ mode. * m4/pthread-mutex.m4 (gl_PTHREAD_MUTEX): Test whether pthread_mutexattr_getrobust exists. If not, define PTHREAD_MUTEXATTR_ROBUST_UNIMPLEMENTED. * lib/pthread-mutex.c (pthread_mutexattr_getrobust, pthread_mutexattr_setrobust): Define also if exists but PTHREAD_MUTEXATTR_ROBUST_UNIMPLEMENTED. * modules/pthread-mutex (configure.ac): Compile pthread-mutex.c also when exists but pthread_mutexattr_getrobust needs a gnulib definition. --- ChangeLog | 13 +++++++++++++ lib/pthread-mutex.c | 19 +++++++++++++++++++ m4/pthread-mutex.m4 | 29 ++++++++++++++++++++++++++++- modules/pthread-mutex | 3 ++- 4 files changed, 62 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1217f31..4d99aca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2019-11-21 Bruno Haible + + pthread-mutex: Fix errors in C++ mode. + * m4/pthread-mutex.m4 (gl_PTHREAD_MUTEX): Test whether + pthread_mutexattr_getrobust exists. If not, define + PTHREAD_MUTEXATTR_ROBUST_UNIMPLEMENTED. + * lib/pthread-mutex.c (pthread_mutexattr_getrobust, + pthread_mutexattr_setrobust): Define also if exists but + PTHREAD_MUTEXATTR_ROBUST_UNIMPLEMENTED. + * modules/pthread-mutex (configure.ac): Compile pthread-mutex.c also + when exists but pthread_mutexattr_getrobust needs a gnulib + definition. + 2019-11-19 Bruno Haible threads-h tests: Fix typo. diff --git a/lib/pthread-mutex.c b/lib/pthread-mutex.c index 7a6fc1a..96a225d 100644 --- a/lib/pthread-mutex.c +++ b/lib/pthread-mutex.c @@ -82,6 +82,25 @@ pthread_mutexattr_destroy (pthread_mutexattr_t *attr _GL_UNUSED) return 0; } +#elif PTHREAD_MUTEXATTR_ROBUST_UNIMPLEMENTED + +int +pthread_mutexattr_getrobust (const pthread_mutexattr_t *attr, int *robustp) +{ + *robustp = PTHREAD_MUTEX_STALLED; + return 0; +} + +int +pthread_mutexattr_setrobust (pthread_mutexattr_t *attr, int robust) +{ + if (!(robust == PTHREAD_MUTEX_STALLED || robust == PTHREAD_MUTEX_ROBUST)) + return EINVAL; + if (!(robust == PTHREAD_MUTEX_STALLED)) + return ENOTSUP; + return 0; +} + #endif #if (defined _WIN32 && ! defined __CYGWIN__) && USE_WINDOWS_THREADS diff --git a/m4/pthread-mutex.m4 b/m4/pthread-mutex.m4 index c7d74f9..abe5f2f 100644 --- a/m4/pthread-mutex.m4 +++ b/m4/pthread-mutex.m4 @@ -1,4 +1,4 @@ -# pthread-mutex.m4 serial 1 +# pthread-mutex.m4 serial 2 dnl Copyright (C) 2019 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -39,6 +39,33 @@ AC_DEFUN([gl_PTHREAD_MUTEX], dnl HAVE_PTHREAD_MUTEX_TIMEDLOCK is set in pthread_mutex_timedlock.m4. HAVE_PTHREAD_MUTEX_UNLOCK=0 HAVE_PTHREAD_MUTEX_DESTROY=0 + else + AC_CACHE_CHECK([for pthread_mutexattr_getrobust], + [gl_cv_func_pthread_mutexattr_getrobust], + [saved_LIBS="$LIBS" + LIBS="$LIBS $LIBMULTITHREAD" + AC_LINK_IFELSE( + [AC_LANG_SOURCE( + [[extern + #ifdef __cplusplus + "C" + #endif + int pthread_mutexattr_getrobust (void); + int main () + { + return pthread_mutexattr_getrobust (); + } + ]])], + [gl_cv_func_pthread_mutexattr_getrobust=yes], + [gl_cv_func_pthread_mutexattr_getrobust=no]) + LIBS="$saved_LIBS" + ]) + if test $gl_cv_func_pthread_mutexattr_getrobust = no; then + HAVE_PTHREAD_MUTEXATTR_GETROBUST=0 + HAVE_PTHREAD_MUTEXATTR_SETROBUST=0 + AC_DEFINE([PTHREAD_MUTEXATTR_ROBUST_UNIMPLEMENTED], [1], + [Define if the 'robust' attribute of pthread_mutex* doesn't exist.]) + fi fi fi ]) diff --git a/modules/pthread-mutex b/modules/pthread-mutex index 8e64a9e..71496b7 100644 --- a/modules/pthread-mutex +++ b/modules/pthread-mutex @@ -13,7 +13,8 @@ windows-timedrecmutex [test $gl_threads_api = windows] configure.ac: gl_PTHREAD_MUTEX -if test $HAVE_PTHREAD_MUTEX_INIT = 0 || test $REPLACE_PTHREAD_MUTEX_INIT = 1; then +if test $HAVE_PTHREAD_MUTEX_INIT = 0 || test $REPLACE_PTHREAD_MUTEX_INIT = 1 \ + || test $HAVE_PTHREAD_MUTEXATTR_GETROBUST = 0 || test $REPLACE_PTHREAD_MUTEXATTR_GETROBUST = 1; then AC_LIBOBJ([pthread-mutex]) fi gl_PTHREAD_MODULE_INDICATOR([pthread-mutex]) -- 2.7.4