libstdc++: Strengthen the check for availability of pthread_rwlock_t
authorJerome Lambourg <lambourg@adacore.com>
Fri, 20 Dec 2019 09:30:48 +0000 (09:30 +0000)
committerJerome Lambourg <lambourg@gcc.gnu.org>
Fri, 20 Dec 2019 09:30:48 +0000 (09:30 +0000)
        * acinclude.m4 (_GLIBCXX_USE_PTHREAD_RWLOCK_T): Checks that
        _PTHREADS is defined after including gthr.h.
        * configure: Regenerate.

From-SVN: r279635

libstdc++-v3/ChangeLog
libstdc++-v3/acinclude.m4
libstdc++-v3/configure

index 91d60d0bff4b604133ae89f34131e34ce3ae84f6..126f3d386b53f838551683945b6df18d8a843c8b 100644 (file)
@@ -1,3 +1,9 @@
+2019-12-20  Jerome Lambourg  <lambourg@adacore.com>
+
+       * acinclude.m4 (_GLIBCXX_USE_PTHREAD_RWLOCK_T): Checks that _PTHREADS
+       is defined after including gthr.h.
+       * configure: Regenerate.
+
 2019-12-12  Jonathan Wakely  <jwakely@redhat.com>
 
        * libsupc++/compare (common_comparison_category): Define without using
index 016b0c583d050804af5d7192ef9f81dac57b0522..8401696b5b5695156456367d853abdc2a7565e83 100644 (file)
@@ -1410,7 +1410,7 @@ AC_DEFUN([GLIBCXX_ENABLE_LIBSTDCXX_TIME], [
           [#include <features.h>],
           [
           #if ! __GLIBC_PREREQ(2, 17)
-          #error 
+          #error
           #endif
           ],
           [glibcxx_glibc217=yes], [glibcxx_glibc217=no])
@@ -2163,7 +2163,7 @@ AC_DEFUN([GLIBCXX_CHECK_STDIO_PROTO], [
   AC_CACHE_VAL(glibcxx_cv_gets, [
   AC_COMPILE_IFELSE([AC_LANG_SOURCE(
          [#include <stdio.h>
-          namespace test 
+          namespace test
           {
               using ::gets;
           }
@@ -2780,9 +2780,9 @@ AC_DEFUN([GLIBCXX_ENABLE_VTABLE_VERIFY], [
     esac
     VTV_PCH_CXXFLAGS="-fvtable-verify=std"
   else
-    VTV_CXXFLAGS= 
+    VTV_CXXFLAGS=
     VTV_PCH_CXXFLAGS=
-    VTV_CXXLINKFLAGS= 
+    VTV_CXXLINKFLAGS=
   fi
 
   AC_SUBST(VTV_CXXFLAGS)
@@ -3964,7 +3964,7 @@ dnl
 AC_DEFUN([GLIBCXX_CHECK_GTHREADS], [
   GLIBCXX_ENABLE(libstdcxx-threads,auto,,[enable C++11 threads support])
 
-  if test x$enable_libstdcxx_threads = xauto || 
+  if test x$enable_libstdcxx_threads = xauto ||
      test x$enable_libstdcxx_threads = xyes; then
 
   AC_LANG_SAVE
@@ -4017,11 +4017,23 @@ AC_DEFUN([GLIBCXX_CHECK_GTHREADS], [
              [Define if gthreads library is available.])
 
     # Also check for pthread_rwlock_t for std::shared_timed_mutex in C++14
-    AC_CHECK_TYPE([pthread_rwlock_t],
-            [AC_DEFINE([_GLIBCXX_USE_PTHREAD_RWLOCK_T], 1,
-            [Define if POSIX read/write locks are available in <gthr.h>.])],
-            [],
-            [#include "gthr.h"])
+    # but only do so if we're using pthread in the gthread library.
+    # On VxWorks for example, pthread_rwlock_t is defined in sys/types.h
+    # but the pthread library is not there by default and the gthread library
+    # does not use it.
+    AC_TRY_COMPILE([#include "gthr.h"],
+    [
+      #if (!defined(_PTHREADS))
+      #error
+      #endif
+    ], [ac_gthread_use_pthreads=yes], [ac_gthread_use_pthreads=no])
+    if test x"$ac_gthread_use_pthreads" = x"yes"; then
+      AC_CHECK_TYPE([pthread_rwlock_t],
+             [AC_DEFINE([_GLIBCXX_USE_PTHREAD_RWLOCK_T], 1,
+             [Define if POSIX read/write locks are available in <gthr.h>.])],
+             [],
+             [#include "gthr.h"])
+    fi
   fi
 
   CXXFLAGS="$ac_save_CXXFLAGS"
index b7242157107f8009de213960b168f8b20c2ba0ef..3c51166fe9fee1885583a3c8749a9f7d3d149df3 100755 (executable)
@@ -74654,7 +74654,33 @@ $as_echo "#define _GLIBCXX_HAS_GTHREADS 1" >>confdefs.h
 
 
     # Also check for pthread_rwlock_t for std::shared_timed_mutex in C++14
-    ac_fn_cxx_check_type "$LINENO" "pthread_rwlock_t" "ac_cv_type_pthread_rwlock_t" "#include \"gthr.h\"
+    # but only do so if we're using pthread in the gthread library.
+    # On VxWorks for example, pthread_rwlock_t is defined in sys/types.h
+    # but the pthread library is not there by default and the gthread library
+    # does not use it.
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include "gthr.h"
+int
+main ()
+{
+
+      #if (!defined(_PTHREADS))
+      #error
+      #endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+  ac_gthread_use_pthreads=yes
+else
+  ac_gthread_use_pthreads=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+    if test x"$ac_gthread_use_pthreads" = x"yes"; then
+      ac_fn_cxx_check_type "$LINENO" "pthread_rwlock_t" "ac_cv_type_pthread_rwlock_t" "#include \"gthr.h\"
 "
 if test "x$ac_cv_type_pthread_rwlock_t" = xyes; then :
 
@@ -74662,6 +74688,7 @@ $as_echo "#define _GLIBCXX_USE_PTHREAD_RWLOCK_T 1" >>confdefs.h
 
 fi
 
+    fi
   fi
 
   CXXFLAGS="$ac_save_CXXFLAGS"