aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/src
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely.gcc@gmail.com>2012-11-23 22:11:23 +0000
committerJonathan Wakely <redi@gcc.gnu.org>2012-11-23 22:11:23 +0000
commitaa66b299c8e766fb453279b55efcdd64d4ef360c (patch)
treebd11ed625b040c97f7b7dc87865300f4d68dbf00 /libstdc++-v3/src
parent9cb5411c1729695a586eaf1d47a42540560387e2 (diff)
downloadgcc-aa66b299c8e766fb453279b55efcdd64d4ef360c.zip
gcc-aa66b299c8e766fb453279b55efcdd64d4ef360c.tar.gz
gcc-aa66b299c8e766fb453279b55efcdd64d4ef360c.tar.bz2
re PR libstdc++/52680 (std::this_thread::sleep_for #ifdef'd out by _GLIBCXX_USE_NANOSLEEP)
PR libstdc++/52680 * acinclude.m4 (GLIBCXX_ENABLE_LIBSTDCXX_TIME): Check for usleep and sleep if nanosleep is not available. Bump libtool revision. * config.h.in: Regenerate. * configure: Likewise. * config/abi/pre/gnu.ver (GLIBCXX_3.4.18): Add __sleep_for. * include/std/thread (this_thread::__sleep_for): Add. (this_thread::yield, this_thread::sleep_until, this_thread::sleep_for): Declare unconditionally. * src/c++11/thread.cc (this_thread::__sleep_for): Define. * testsuite/lib/libstdc++.exp (check_v3_target_nanosleep): Rename to check_v3_target_sleep. * testsuite/lib/dg-options.exp (dg-require-nanosleep): Rename to dg-require-sleep. * testsuite/30_threads/condition_variable_any/53830.cc: Update. * testsuite/30_threads/this_thread/2.cc: Likewise. * testsuite/30_threads/this_thread/3.cc: Likewise. * testsuite/30_threads/this_thread/4.cc: Likewise. * testsuite/30_threads/async/54297.cc: Likewise. From-SVN: r193769
Diffstat (limited to 'libstdc++-v3/src')
-rw-r--r--libstdc++-v3/src/c++11/thread.cc48
1 files changed, 46 insertions, 2 deletions
diff --git a/libstdc++-v3/src/c++11/thread.cc b/libstdc++-v3/src/c++11/thread.cc
index 5c10832..084be42 100644
--- a/libstdc++-v3/src/c++11/thread.cc
+++ b/libstdc++-v3/src/c++11/thread.cc
@@ -1,6 +1,6 @@
// thread -*- C++ -*-
-// Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+// Copyright (C) 2008-2012 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
@@ -27,6 +27,8 @@
#include <system_error>
#include <cerrno>
+#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
+
#if defined(_GLIBCXX_USE_GET_NPROCS)
# include <sys/sysinfo.h>
# define _GLIBCXX_NPROCS get_nprocs()
@@ -55,7 +57,13 @@ static inline int get_nprocs()
# define _GLIBCXX_NPROCS 0
#endif
-#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
+#ifndef _GLIBCXX_USE_NANOSLEEP
+# ifdef _GLIBCXX_HAVE_SLEEP
+# include <unistd.h>
+# else
+# error "No sleep function known for this target"
+# endif
+#endif
namespace std _GLIBCXX_VISIBILITY(default)
{
@@ -142,6 +150,42 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
_GLIBCXX_END_NAMESPACE_VERSION
+
+namespace this_thread
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
+ void
+ __sleep_for(chrono::seconds __s, chrono::nanoseconds __ns)
+ {
+#ifdef _GLIBCXX_USE_NANOSLEEP
+ __gthread_time_t __ts =
+ {
+ static_cast<std::time_t>(__s.count()),
+ static_cast<long>(__ns.count())
+ };
+ ::nanosleep(&__ts, 0);
+#else
+# ifdef _GLIBCXX_HAVE_SLEEP
+# ifdef _GLIBCXX_HAVE_USLEEP
+ ::sleep(__s.count());
+ if (__ns.count() > 0)
+ {
+ long __us = __ns.count() / 1000;
+ if (__us == 0)
+ __us = 1;
+ ::usleep(__us);
+ }
+# else
+ ::sleep(__s.count() + (__ns >= 1000000));
+# endif
+# endif
+#endif
+ }
+
+_GLIBCXX_END_NAMESPACE_VERSION
+}
+
} // namespace std
#endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1