Let std::thread check pass even without pthreads
authorTom Tromey <tromey@adacore.com>
Thu, 31 Mar 2022 14:26:12 +0000 (08:26 -0600)
committerTom Tromey <tromey@adacore.com>
Thu, 14 Apr 2022 15:28:56 +0000 (09:28 -0600)
Currently, the configure check for std::thread relies on pthreads
existing.  However, this means that if std::thread is implemented for
a non-pthreads host, then the check will yield the wrong answer.  This
happened in AdaCore internal builds.  Here, we have this GCC patch:

    https://gcc.gnu.org/legacy-ml/gcc-patches/2019-06/msg01840.html

... which adds mingw support to GCC's gthreads implementation, and
also to std::thread.

This configure change fixes this problem and enables threading for
gdb.

gdb/configure
gdbserver/configure
gdbsupport/common.m4
gdbsupport/configure

index 7ae8a2a3f3fc7cc1513c5d9c5b9b131e07fb4423..7225c7fc60dea25314db2d0df954a69e2a2cfbc3 100755 (executable)
@@ -14668,12 +14668,11 @@ ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ex
 ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
 
 
-  if test "$threads" = "yes"; then
-    save_LIBS="$LIBS"
-    LIBS="$PTHREAD_LIBS $LIBS"
-    save_CXXFLAGS="$CXXFLAGS"
-    CXXFLAGS="$PTHREAD_CFLAGS $save_CXXFLAGS"
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for std::thread" >&5
+  save_LIBS="$LIBS"
+  LIBS="$PTHREAD_LIBS $LIBS"
+  save_CXXFLAGS="$CXXFLAGS"
+  CXXFLAGS="$PTHREAD_CFLAGS $save_CXXFLAGS"
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for std::thread" >&5
 $as_echo_n "checking for std::thread... " >&6; }
 if ${gdb_cv_cxx_std_thread+:} false; then :
   $as_echo_n "(cached) " >&6
@@ -14681,7 +14680,7 @@ else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include <thread>
-      void callback() { }
+    void callback() { }
 int
 main ()
 {
@@ -14700,6 +14699,7 @@ fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gdb_cv_cxx_std_thread" >&5
 $as_echo "$gdb_cv_cxx_std_thread" >&6; }
 
+  if test "$threads" = "yes"; then
     # This check must be here, while LIBS includes any necessary
     # threading library.
     for ac_func in pthread_sigmask pthread_setname_np
@@ -14714,10 +14714,9 @@ _ACEOF
 fi
 done
 
-
-    LIBS="$save_LIBS"
-    CXXFLAGS="$save_CXXFLAGS"
   fi
+  LIBS="$save_LIBS"
+  CXXFLAGS="$save_CXXFLAGS"
 
   if test "$want_threading" = "yes"; then
     if test "$gdb_cv_cxx_std_thread" = "yes"; then
index bcb15941ed127774fbfc7a354f68ccac0f77bf23..e6b46c24588bb136bc087514e0ae13e2db686095 100755 (executable)
@@ -7930,12 +7930,11 @@ ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ex
 ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
 
 
-  if test "$threads" = "yes"; then
-    save_LIBS="$LIBS"
-    LIBS="$PTHREAD_LIBS $LIBS"
-    save_CXXFLAGS="$CXXFLAGS"
-    CXXFLAGS="$PTHREAD_CFLAGS $save_CXXFLAGS"
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for std::thread" >&5
+  save_LIBS="$LIBS"
+  LIBS="$PTHREAD_LIBS $LIBS"
+  save_CXXFLAGS="$CXXFLAGS"
+  CXXFLAGS="$PTHREAD_CFLAGS $save_CXXFLAGS"
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for std::thread" >&5
 $as_echo_n "checking for std::thread... " >&6; }
 if ${gdb_cv_cxx_std_thread+:} false; then :
   $as_echo_n "(cached) " >&6
@@ -7943,7 +7942,7 @@ else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include <thread>
-      void callback() { }
+    void callback() { }
 int
 main ()
 {
@@ -7962,6 +7961,7 @@ fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gdb_cv_cxx_std_thread" >&5
 $as_echo "$gdb_cv_cxx_std_thread" >&6; }
 
+  if test "$threads" = "yes"; then
     # This check must be here, while LIBS includes any necessary
     # threading library.
     for ac_func in pthread_sigmask pthread_setname_np
@@ -7976,10 +7976,9 @@ _ACEOF
 fi
 done
 
-
-    LIBS="$save_LIBS"
-    CXXFLAGS="$save_CXXFLAGS"
   fi
+  LIBS="$save_LIBS"
+  CXXFLAGS="$save_CXXFLAGS"
 
   if test "$want_threading" = "yes"; then
     if test "$gdb_cv_cxx_std_thread" = "yes"; then
index 838c01c00daf4a014ab653a7702ddd0b100cf629..d3e9ecbe823831e980004cfe30afb333fdecd477 100644 (file)
@@ -93,27 +93,26 @@ AC_DEFUN([GDB_AC_COMMON], [
   # mingw and DJGPP.
   AC_LANG_PUSH([C++])
   AX_PTHREAD([threads=yes], [threads=no])
-  if test "$threads" = "yes"; then
-    save_LIBS="$LIBS"
-    LIBS="$PTHREAD_LIBS $LIBS"
-    save_CXXFLAGS="$CXXFLAGS"
-    CXXFLAGS="$PTHREAD_CFLAGS $save_CXXFLAGS"
-    AC_CACHE_CHECK([for std::thread],
-                  gdb_cv_cxx_std_thread,
-                  [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
-    [[#include <thread>
-      void callback() { }]],
-    [[std::thread t(callback);]])],
-                                 gdb_cv_cxx_std_thread=yes,
-                                 gdb_cv_cxx_std_thread=no)])
+  save_LIBS="$LIBS"
+  LIBS="$PTHREAD_LIBS $LIBS"
+  save_CXXFLAGS="$CXXFLAGS"
+  CXXFLAGS="$PTHREAD_CFLAGS $save_CXXFLAGS"
+  AC_CACHE_CHECK([for std::thread],
+                gdb_cv_cxx_std_thread,
+                [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
+  [[#include <thread>
+    void callback() { }]],
+  [[std::thread t(callback);]])],
+                               gdb_cv_cxx_std_thread=yes,
+                               gdb_cv_cxx_std_thread=no)])
 
+  if test "$threads" = "yes"; then
     # This check must be here, while LIBS includes any necessary
     # threading library.
     AC_CHECK_FUNCS([pthread_sigmask pthread_setname_np])
-
-    LIBS="$save_LIBS"
-    CXXFLAGS="$save_CXXFLAGS"
   fi
+  LIBS="$save_LIBS"
+  CXXFLAGS="$save_CXXFLAGS"
 
   if test "$want_threading" = "yes"; then
     if test "$gdb_cv_cxx_std_thread" = "yes"; then
index 2070a39fbb70895a8731d8e13466c2983f603058..618f487749f527673196325512400dab844cb1d0 100755 (executable)
@@ -8945,12 +8945,11 @@ ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ex
 ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
 
 
-  if test "$threads" = "yes"; then
-    save_LIBS="$LIBS"
-    LIBS="$PTHREAD_LIBS $LIBS"
-    save_CXXFLAGS="$CXXFLAGS"
-    CXXFLAGS="$PTHREAD_CFLAGS $save_CXXFLAGS"
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for std::thread" >&5
+  save_LIBS="$LIBS"
+  LIBS="$PTHREAD_LIBS $LIBS"
+  save_CXXFLAGS="$CXXFLAGS"
+  CXXFLAGS="$PTHREAD_CFLAGS $save_CXXFLAGS"
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for std::thread" >&5
 $as_echo_n "checking for std::thread... " >&6; }
 if ${gdb_cv_cxx_std_thread+:} false; then :
   $as_echo_n "(cached) " >&6
@@ -8958,7 +8957,7 @@ else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include <thread>
-      void callback() { }
+    void callback() { }
 int
 main ()
 {
@@ -8977,6 +8976,7 @@ fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gdb_cv_cxx_std_thread" >&5
 $as_echo "$gdb_cv_cxx_std_thread" >&6; }
 
+  if test "$threads" = "yes"; then
     # This check must be here, while LIBS includes any necessary
     # threading library.
     for ac_func in pthread_sigmask pthread_setname_np
@@ -8991,10 +8991,9 @@ _ACEOF
 fi
 done
 
-
-    LIBS="$save_LIBS"
-    CXXFLAGS="$save_CXXFLAGS"
   fi
+  LIBS="$save_LIBS"
+  CXXFLAGS="$save_CXXFLAGS"
 
   if test "$want_threading" = "yes"; then
     if test "$gdb_cv_cxx_std_thread" = "yes"; then