From aa66b299c8e766fb453279b55efcdd64d4ef360c Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Fri, 23 Nov 2012 22:11:23 +0000 Subject: 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 --- libstdc++-v3/src/c++11/thread.cc | 48 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) (limited to 'libstdc++-v3/src') 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 #include +#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1) + #if defined(_GLIBCXX_USE_GET_NPROCS) # include # 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 +# 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(__s.count()), + static_cast(__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 -- cgit v1.1