public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-5887] libstdc++: Fix build failure for target with no way to sleep
@ 2020-12-09 16:59 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2020-12-09 16:59 UTC (permalink / raw)
  To: gcc-cvs, libstdc++-cvs

https://gcc.gnu.org/g:0aa1786d34b891c8e1e219fb11255af5358013c4

commit r11-5887-g0aa1786d34b891c8e1e219fb11255af5358013c4
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Dec 9 16:53:18 2020 +0000

    libstdc++: Fix build failure for target with no way to sleep
    
    In previous releases the std::this_thread::sleep_for function was only
    declared if the target supports multiple threads. I changed that
    recently in r11-2649-g5bbb1f3000c57fd4d95969b30fa0e35be6d54ffb so that
    sleep_for could be used single-threaded. But that means that targets
    using --disable-threads are now required to provide some way to sleep.
    This breaks the build for (at least) AVR when trying to build a hosted
    library.
    
    This patch adds a new autoconf macro that is defined when no way to
    sleep is available, and uses that to suppress the sleeping functions in
    std::this_thread.
    
    The #error in src/c++11/thread.cc is retained for the case where there
    is no sleep function available but multiple threads are supported. This
    is consistent with previous releases, but that #error could probably be
    removed without any consequences.
    
    libstdc++-v3/ChangeLog:
    
            * acinclude.m4 (GLIBCXX_ENABLE_LIBSTDCXX_TIME): Define NO_SLEEP
            if none of nanosleep, sleep and Sleep is available.
            * config.h.in: Regenerate.
            * configure: Regenerate.
            * include/std/thread [_GLIBCXX_NO_SLEEP] (__sleep_for): Do
            not declare.
            [_GLIBCXX_NO_SLEEP] (sleep_for, sleep_until): Do not
            define.
            * src/c++11/thread.cc [_GLIBCXX_NO_SLEEP] (__sleep_for): Do
            not define.

Diff:
---
 libstdc++-v3/acinclude.m4        | 6 ++++++
 libstdc++-v3/config.h.in         | 3 +++
 libstdc++-v3/configure           | 8 ++++++++
 libstdc++-v3/include/std/thread  | 7 ++++++-
 libstdc++-v3/src/c++11/thread.cc | 5 ++++-
 5 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
index fcd9ea3d23a..61191812c92 100644
--- a/libstdc++-v3/acinclude.m4
+++ b/libstdc++-v3/acinclude.m4
@@ -1626,16 +1626,22 @@ AC_DEFUN([GLIBCXX_ENABLE_LIBSTDCXX_TIME], [
   fi
 
   if test x"$ac_has_nanosleep$ac_has_sleep" = x"nono"; then
+      ac_no_sleep=yes
       AC_MSG_CHECKING([for Sleep])
       AC_TRY_COMPILE([#include <windows.h>],
                      [Sleep(1)],
                      [ac_has_win32_sleep=yes],[ac_has_win32_sleep=no])
       if test x"$ac_has_win32_sleep" = x"yes"; then
         AC_DEFINE(HAVE_WIN32_SLEEP,1, [Defined if Sleep exists.])
+	ac_no_sleep=no
       fi
       AC_MSG_RESULT($ac_has_win32_sleep)
   fi
 
+  if test x"$ac_no_sleep" = x"yes"; then
+    AC_DEFINE(NO_SLEEP,1, [Defined if no way to sleep is available.])
+  fi
+
   AC_SUBST(GLIBCXX_LIBS)
 
   CXXFLAGS="$ac_save_CXXFLAGS"
diff --git a/libstdc++-v3/config.h.in b/libstdc++-v3/config.h.in
index 72faabfb2c1..17b11997d48 100644
--- a/libstdc++-v3/config.h.in
+++ b/libstdc++-v3/config.h.in
@@ -767,6 +767,9 @@
    */
 #undef LT_OBJDIR
 
+/* Defined if no way to sleep is available. */
+#undef NO_SLEEP
+
 /* Name of package */
 #undef PACKAGE
 
diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure
index d128de2f186..d7a4826b8e2 100755
--- a/libstdc++-v3/configure
+++ b/libstdc++-v3/configure
@@ -21751,6 +21751,7 @@ $as_echo "$ac_has_usleep" >&6; }
   fi
 
   if test x"$ac_has_nanosleep$ac_has_sleep" = x"nono"; then
+      ac_no_sleep=yes
       { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Sleep" >&5
 $as_echo_n "checking for Sleep... " >&6; }
       cat confdefs.h - <<_ACEOF >conftest.$ac_ext
@@ -21774,11 +21775,18 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 
 $as_echo "#define HAVE_WIN32_SLEEP 1" >>confdefs.h
 
+	ac_no_sleep=no
       fi
       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_has_win32_sleep" >&5
 $as_echo "$ac_has_win32_sleep" >&6; }
   fi
 
+  if test x"$ac_no_sleep" = x"yes"; then
+
+$as_echo "#define NO_SLEEP 1" >>confdefs.h
+
+  fi
+
 
 
   CXXFLAGS="$ac_save_CXXFLAGS"
diff --git a/libstdc++-v3/include/std/thread b/libstdc++-v3/include/std/thread
index 6ea8a51c0cf..8d0ede2b6c2 100644
--- a/libstdc++-v3/include/std/thread
+++ b/libstdc++-v3/include/std/thread
@@ -122,8 +122,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    */
   namespace this_thread
   {
+#ifndef _GLIBCXX_NO_SLEEP
+
+#ifndef _GLIBCXX_USE_NANOSLEEP
     void
     __sleep_for(chrono::seconds, chrono::nanoseconds);
+#endif
 
     /// this_thread::sleep_for
     template<typename _Rep, typename _Period>
@@ -168,7 +172,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	    __now = _Clock::now();
 	  }
       }
-  }
+  } // namespace this_thread
+#endif // ! NO_SLEEP
 
 #ifdef __cpp_lib_jthread
 
diff --git a/libstdc++-v3/src/c++11/thread.cc b/libstdc++-v3/src/c++11/thread.cc
index a9c92804959..62f6ddcd802 100644
--- a/libstdc++-v3/src/c++11/thread.cc
+++ b/libstdc++-v3/src/c++11/thread.cc
@@ -35,7 +35,8 @@
 #  include <unistd.h>
 # elif defined(_GLIBCXX_HAVE_WIN32_SLEEP)
 #  include <windows.h>
-# else
+# elif defined _GLIBCXX_NO_SLEEP && defined _GLIBCXX_HAS_GTHREADS
+// We expect to be able to sleep for targets that support multiple threads:
 #  error "No sleep function known for this target"
 # endif
 #endif
@@ -196,6 +197,7 @@ _GLIBCXX_END_NAMESPACE_VERSION
 
 #endif // _GLIBCXX_HAS_GTHREADS
 
+#ifndef _GLIBCXX_NO_SLEEP
 namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
@@ -252,3 +254,4 @@ namespace this_thread
 }
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace std
+#endif // ! NO_SLEEP


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-12-09 16:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-09 16:59 [gcc r11-5887] libstdc++: Fix build failure for target with no way to sleep 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).