public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch] libstdc++/configure: strengthen the check for availability of pthread_rwlock_t
@ 2019-12-17  9:09 Jérôme Lambourg
  2019-12-19 11:29 ` Jonathan Wakely
  0 siblings, 1 reply; 2+ messages in thread
From: Jérôme Lambourg @ 2019-12-17  9:09 UTC (permalink / raw)
  To: gcc-patches, libstdc++

[-- Attachment #1: Type: text/plain, Size: 1133 bytes --]

Hello,

This patch to libstdc++ configure ensures that pthread_rwlock_t is used only
when pthread is used for gthreads implementation.

The original issue is that VxWorks comes with its native tasking layer and an
optional pthread layer built above it. As pthread is an optional feature of the
kernel it may not be available on the target board.

Now, even being optional, the headers are present in the development
environment, and are in particular partially available when including the main
vxWorks.h header, and so are detected automatically as available by libstdc++.

This patch will thus refine the check and will make configure try to use
pthread_rwlock_t only when the gthr library already relies on pthread.

This was of course tested with vxworks targets, and we also verified that this
does not impact Linux (that uses pthread) or Windows (that does not use
pthread).

Best regards,
- Jerome

2019-12-16  Jerome Lambourg  <lambourg@adacore.com>

libstdc++
	* acinclude.m4 (_GLIBCXX_USE_PTHREAD_RWLOCK_T): Checks that _PTHREADS
	is defined after including gthr.h.
	* configure: Regenerate.


[-- Attachment #2: pthread_rwlock_libstdcxx_configure.patch --]
[-- Type: application/octet-stream, Size: 2462 bytes --]

diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
index 016b0c583d0..8401696b5b5 100644
--- a/libstdc++-v3/acinclude.m4
+++ b/libstdc++-v3/acinclude.m4
@@ -4017,12 +4017,24 @@ 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
+    # 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"
   AC_LANG_RESTORE
diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure
index b7242157107..3c51166fe9f 100755
--- a/libstdc++-v3/configure
+++ b/libstdc++-v3/configure
@@ -74654,6 +74654,32 @@ $as_echo "#define _GLIBCXX_HAS_GTHREADS 1" >>confdefs.h
 
 
     # Also check for pthread_rwlock_t for std::shared_timed_mutex in C++14
+    # 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 :
@@ -74663,6 +74689,7 @@ $as_echo "#define _GLIBCXX_USE_PTHREAD_RWLOCK_T 1" >>confdefs.h
 fi
 
     fi
+  fi
 
   CXXFLAGS="$ac_save_CXXFLAGS"
   ac_ext=c

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [patch] libstdc++/configure: strengthen the check for availability of pthread_rwlock_t
  2019-12-17  9:09 [patch] libstdc++/configure: strengthen the check for availability of pthread_rwlock_t Jérôme Lambourg
@ 2019-12-19 11:29 ` Jonathan Wakely
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2019-12-19 11:29 UTC (permalink / raw)
  To: Jérôme Lambourg; +Cc: gcc-patches, libstdc++

On 17/12/19 10:04 +0100, Jérôme Lambourg wrote:
>Hello,
>
>This patch to libstdc++ configure ensures that pthread_rwlock_t is used only
>when pthread is used for gthreads implementation.
>
>The original issue is that VxWorks comes with its native tasking layer and an
>optional pthread layer built above it. As pthread is an optional feature of the
>kernel it may not be available on the target board.
>
>Now, even being optional, the headers are present in the development
>environment, and are in particular partially available when including the main
>vxWorks.h header, and so are detected automatically as available by libstdc++.
>
>This patch will thus refine the check and will make configure try to use
>pthread_rwlock_t only when the gthr library already relies on pthread.
>
>This was of course tested with vxworks targets, and we also verified that this
>does not impact Linux (that uses pthread) or Windows (that does not use
>pthread).

OK for trunk, thanks.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-12-19 11:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-17  9:09 [patch] libstdc++/configure: strengthen the check for availability of pthread_rwlock_t Jérôme Lambourg
2019-12-19 11:29 ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).