summaryrefslogtreecommitdiffstats
path: root/libstdc++-v3/src
diff options
context:
space:
mode:
authorredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>2012-11-23 22:11:23 +0000
committerredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>2012-11-23 22:11:23 +0000
commita2bb721d8e1a576841fb80f1c78f0694014d4e8b (patch)
treebd11ed625b040c97f7b7dc87865300f4d68dbf00 /libstdc++-v3/src
parent66ee291faa52558caedbc214d662b7b7742eca7e (diff)
downloadppe42-gcc-a2bb721d8e1a576841fb80f1c78f0694014d4e8b.tar.gz
ppe42-gcc-a2bb721d8e1a576841fb80f1c78f0694014d4e8b.zip
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@193769 138bc75d-0d04-0410-961f-82ee72b054a4
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 5c108324141..084be426118 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
OpenPOWER on IntegriCloud