Commit aa66b299 by Jonathan Wakely Committed by Jonathan Wakely

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
parent 9cb5411c
2012-11-23 Jonathan Wakely <jwakely.gcc@gmail.com>
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.
2012-11-20 Paolo Carlini <paolo.carlini@oracle.com> 2012-11-20 Paolo Carlini <paolo.carlini@oracle.com>
PR libstdc++/55413 PR libstdc++/55413
......
...@@ -1281,6 +1281,24 @@ AC_DEFUN([GLIBCXX_ENABLE_LIBSTDCXX_TIME], [ ...@@ -1281,6 +1281,24 @@ AC_DEFUN([GLIBCXX_ENABLE_LIBSTDCXX_TIME], [
if test x"$ac_has_nanosleep" = x"yes"; then if test x"$ac_has_nanosleep" = x"yes"; then
AC_DEFINE(_GLIBCXX_USE_NANOSLEEP, 1, AC_DEFINE(_GLIBCXX_USE_NANOSLEEP, 1,
[ Defined if nanosleep is available. ]) [ Defined if nanosleep is available. ])
else
AC_MSG_CHECKING([for sleep])
AC_TRY_COMPILE([#include <unistd.h>],
[sleep(1)],
[ac_has_sleep=yes],[ac_has_sleep=no])
if test x"$ac_has_sleep" = x"yes"; then
AC_DEFINE(HAVE_SLEEP,1, [Defined if sleep exists.])
fi
AC_MSG_RESULT($ac_has_sleep)
AC_MSG_CHECKING([for usleep])
AC_TRY_COMPILE([#include <unistd.h>],
[sleep(1);
usleep(100);],
[ac_has_usleep=yes],[ac_has_usleep=no])
if test x"$ac_has_usleep" = x"yes"; then
AC_DEFINE(HAVE_USLEEP,1, [Defined if usleep exists.])
fi
AC_MSG_RESULT($ac_has_usleep)
fi fi
AC_SUBST(GLIBCXX_LIBS) AC_SUBST(GLIBCXX_LIBS)
...@@ -3201,7 +3219,7 @@ changequote([,])dnl ...@@ -3201,7 +3219,7 @@ changequote([,])dnl
fi fi
# For libtool versioning info, format is CURRENT:REVISION:AGE # For libtool versioning info, format is CURRENT:REVISION:AGE
libtool_VERSION=6:17:0 libtool_VERSION=6:18:0
# Everything parsed; figure out what files and settings to use. # Everything parsed; figure out what files and settings to use.
case $enable_symvers in case $enable_symvers in
......
...@@ -327,6 +327,9 @@ ...@@ -327,6 +327,9 @@
/* Define to 1 if you have the `sinl' function. */ /* Define to 1 if you have the `sinl' function. */
#undef HAVE_SINL #undef HAVE_SINL
/* Defined if sleep exists. */
#undef HAVE_SLEEP
/* Define to 1 if you have the `sqrtf' function. */ /* Define to 1 if you have the `sqrtf' function. */
#undef HAVE_SQRTF #undef HAVE_SQRTF
...@@ -436,6 +439,9 @@ ...@@ -436,6 +439,9 @@
/* Define to 1 if you have the <unistd.h> header file. */ /* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H #undef HAVE_UNISTD_H
/* Defined if usleep exists. */
#undef HAVE_USLEEP
/* Defined if vfwscanf exists. */ /* Defined if vfwscanf exists. */
#undef HAVE_VFWSCANF #undef HAVE_VFWSCANF
......
...@@ -1339,6 +1339,9 @@ GLIBCXX_3.4.18 { ...@@ -1339,6 +1339,9 @@ GLIBCXX_3.4.18 {
# construction vtable # construction vtable
_ZTCSt*; _ZTCSt*;
# std::this_thread::__sleep_for
_ZNSt11this_thread11__sleep_for*;
} GLIBCXX_3.4.17; } GLIBCXX_3.4.17;
# Symbols in the support library (libsupc++) have their own tag. # Symbols in the support library (libsupc++) have their own tag.
......
...@@ -19844,6 +19844,60 @@ $as_echo "#define _GLIBCXX_USE_CLOCK_REALTIME 1" >>confdefs.h ...@@ -19844,6 +19844,60 @@ $as_echo "#define _GLIBCXX_USE_CLOCK_REALTIME 1" >>confdefs.h
$as_echo "#define _GLIBCXX_USE_NANOSLEEP 1" >>confdefs.h $as_echo "#define _GLIBCXX_USE_NANOSLEEP 1" >>confdefs.h
else
{ $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
/* end confdefs.h. */
#include <unistd.h>
int
main ()
{
sleep(1)
;
return 0;
}
_ACEOF
if ac_fn_cxx_try_compile "$LINENO"; then :
ac_has_sleep=yes
else
ac_has_sleep=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
if test x"$ac_has_sleep" = x"yes"; then
$as_echo "#define HAVE_SLEEP 1" >>confdefs.h
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_has_sleep" >&5
$as_echo "$ac_has_sleep" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for usleep" >&5
$as_echo_n "checking for usleep... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <unistd.h>
int
main ()
{
sleep(1);
usleep(100);
;
return 0;
}
_ACEOF
if ac_fn_cxx_try_compile "$LINENO"; then :
ac_has_usleep=yes
else
ac_has_usleep=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
if test x"$ac_has_usleep" = x"yes"; then
$as_echo "#define HAVE_USLEEP 1" >>confdefs.h
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_has_usleep" >&5
$as_echo "$ac_has_usleep" >&6; }
fi fi
...@@ -70449,7 +70503,7 @@ $as_echo "$as_me: WARNING: === Symbol versioning will be disabled." >&2;} ...@@ -70449,7 +70503,7 @@ $as_echo "$as_me: WARNING: === Symbol versioning will be disabled." >&2;}
fi fi
# For libtool versioning info, format is CURRENT:REVISION:AGE # For libtool versioning info, format is CURRENT:REVISION:AGE
libtool_VERSION=6:17:0 libtool_VERSION=6:18:0
# Everything parsed; figure out what files and settings to use. # Everything parsed; figure out what files and settings to use.
case $enable_symvers in case $enable_symvers in
...@@ -251,32 +251,35 @@ _GLIBCXX_END_NAMESPACE_VERSION ...@@ -251,32 +251,35 @@ _GLIBCXX_END_NAMESPACE_VERSION
inline thread::id inline thread::id
get_id() noexcept { return thread::id(__gthread_self()); } get_id() noexcept { return thread::id(__gthread_self()); }
#ifdef _GLIBCXX_USE_SCHED_YIELD
/// yield /// yield
inline void inline void
yield() noexcept yield() noexcept
{ __gthread_yield(); } {
#ifdef _GLIBCXX_USE_SCHED_YIELD
__gthread_yield();
#endif #endif
}
void
__sleep_for(chrono::seconds, chrono::nanoseconds);
#ifdef _GLIBCXX_USE_NANOSLEEP
/// sleep_for /// sleep_for
template<typename _Rep, typename _Period> template<typename _Rep, typename _Period>
inline void inline void
sleep_for(const chrono::duration<_Rep, _Period>& __rtime) sleep_for(const chrono::duration<_Rep, _Period>& __rtime)
{ {
chrono::seconds __s = auto __s = chrono::duration_cast<chrono::seconds>(__rtime);
chrono::duration_cast<chrono::seconds>(__rtime); auto __ns = chrono::duration_cast<chrono::nanoseconds>(__rtime - __s);
#ifdef _GLIBCXX_USE_NANOSLEEP
chrono::nanoseconds __ns =
chrono::duration_cast<chrono::nanoseconds>(__rtime - __s);
__gthread_time_t __ts = __gthread_time_t __ts =
{ {
static_cast<std::time_t>(__s.count()), static_cast<std::time_t>(__s.count()),
static_cast<long>(__ns.count()) static_cast<long>(__ns.count())
}; };
::nanosleep(&__ts, 0); ::nanosleep(&__ts, 0);
#else
__sleep_for(__s, __ns);
#endif
} }
/// sleep_until /// sleep_until
...@@ -284,7 +287,6 @@ _GLIBCXX_END_NAMESPACE_VERSION ...@@ -284,7 +287,6 @@ _GLIBCXX_END_NAMESPACE_VERSION
inline void inline void
sleep_until(const chrono::time_point<_Clock, _Duration>& __atime) sleep_until(const chrono::time_point<_Clock, _Duration>& __atime)
{ sleep_for(__atime - _Clock::now()); } { sleep_for(__atime - _Clock::now()); }
#endif
_GLIBCXX_END_NAMESPACE_VERSION _GLIBCXX_END_NAMESPACE_VERSION
} }
......
// thread -*- C++ -*- // 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 // 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 // software; you can redistribute it and/or modify it under the
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
#include <system_error> #include <system_error>
#include <cerrno> #include <cerrno>
#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
#if defined(_GLIBCXX_USE_GET_NPROCS) #if defined(_GLIBCXX_USE_GET_NPROCS)
# include <sys/sysinfo.h> # include <sys/sysinfo.h>
# define _GLIBCXX_NPROCS get_nprocs() # define _GLIBCXX_NPROCS get_nprocs()
...@@ -55,7 +57,13 @@ static inline int get_nprocs() ...@@ -55,7 +57,13 @@ static inline int get_nprocs()
# define _GLIBCXX_NPROCS 0 # define _GLIBCXX_NPROCS 0
#endif #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) namespace std _GLIBCXX_VISIBILITY(default)
{ {
...@@ -142,6 +150,42 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -142,6 +150,42 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
} }
_GLIBCXX_END_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 } // namespace std
#endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1 #endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
// { dg-require-cstdint "" } // { dg-require-cstdint "" }
// { dg-require-gthreads "" } // { dg-require-gthreads "" }
// { dg-require-atomic-builtins "" } // { dg-require-atomic-builtins "" }
// { dg-require-nanosleep "" } // { dg-require-sleep "" }
// Copyright (C) 2012 Free Software Foundation, Inc. // Copyright (C) 2012 Free Software Foundation, Inc.
// //
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
// { dg-require-cstdint "" } // { dg-require-cstdint "" }
// { dg-require-gthreads "" } // { dg-require-gthreads "" }
// { dg-require-sched-yield "" } // { dg-require-sched-yield "" }
// { dg-require-nanosleep "" } // { dg-require-sleep "" }
// Copyright (C) 2012 Free Software Foundation, Inc. // Copyright (C) 2012 Free Software Foundation, Inc.
// //
......
...@@ -4,9 +4,8 @@ ...@@ -4,9 +4,8 @@
// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } } // { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
// { dg-require-cstdint "" } // { dg-require-cstdint "" }
// { dg-require-gthreads "" } // { dg-require-gthreads "" }
// { dg-require-sched-yield "" }
// Copyright (C) 2008, 2009, 2010, 2011, 2012 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 // 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 // software; you can redistribute it and/or modify it under the
......
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } } // { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
// { dg-require-cstdint "" } // { dg-require-cstdint "" }
// { dg-require-gthreads "" } // { dg-require-gthreads "" }
// { dg-require-nanosleep "" } // { dg-require-sleep "" }
// Copyright (C) 2008, 2009, 2010, 2011, 2012 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 // 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 // software; you can redistribute it and/or modify it under the
......
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } } // { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
// { dg-require-cstdint "" } // { dg-require-cstdint "" }
// { dg-require-gthreads "" } // { dg-require-gthreads "" }
// { dg-require-nanosleep "" } // { dg-require-sleep "" }
// Copyright (C) 2008, 2009, 2010, 2011, 2012 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 // 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 // software; you can redistribute it and/or modify it under the
......
...@@ -143,8 +143,8 @@ proc dg-require-gthreads-timed { args } { ...@@ -143,8 +143,8 @@ proc dg-require-gthreads-timed { args } {
return return
} }
proc dg-require-nanosleep { args } { proc dg-require-sleep { args } {
if { ![ check_v3_target_nanosleep ] } { if { ![ check_v3_target_sleep ] } {
upvar dg-do-what dg-do-what upvar dg-do-what dg-do-what
set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"] set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
return return
......
...@@ -1352,41 +1352,43 @@ proc check_v3_target_gthreads_timed { } { ...@@ -1352,41 +1352,43 @@ proc check_v3_target_gthreads_timed { } {
} }
proc check_v3_target_nanosleep { } { proc check_v3_target_sleep { } {
global cxxflags global cxxflags
global DEFAULT_CXXFLAGS global DEFAULT_CXXFLAGS
global et_nanosleep global et_sleep
global tool global tool
if { ![info exists et_nanosleep_target_name] } { if { ![info exists et_sleep_target_name] } {
set et_nanosleep_target_name "" set et_sleep_target_name ""
} }
# If the target has changed since we set the cached value, clear it. # If the target has changed since we set the cached value, clear it.
set current_target [current_target_name] set current_target [current_target_name]
if { $current_target != $et_nanosleep_target_name } { if { $current_target != $et_sleep_target_name } {
verbose "check_v3_target_nanosleep: `$et_nanosleep_target_name'" 2 verbose "check_v3_target_sleep: `$et_sleep_target_name'" 2
set et_nanosleep_target_name $current_target set et_sleep_target_name $current_target
if [info exists et_nanosleep] { if [info exists et_sleep] {
verbose "check_v3_target_nanosleep: removing cached result" 2 verbose "check_v3_target_sleep: removing cached result" 2
unset et_nanosleep unset et_sleep
} }
} }
if [info exists et_nanosleep] { if [info exists et_sleep] {
verbose "check_v3_target_nanosleep: using cached result" 2 verbose "check_v3_target_sleep: using cached result" 2
} else { } else {
set et_nanosleep 0 set et_sleep 0
# Set up and preprocess a C++0x test program that depends # Set up and preprocess a C++11 test program that depends
# on the nanosleep facilities to be available. # on the sleep facilities to be available.
set src nanosleep[pid].cc set src sleep[pid].cc
set f [open $src "w"] set f [open $src "w"]
puts $f "#include <bits/c++config.h>" puts $f "#include <bits/c++config.h>"
puts $f "#ifndef _GLIBCXX_USE_NANOSLEEP" puts $f "#ifndef _GLIBCXX_USE_NANOSLEEP"
puts $f "# error No nanosleep" puts $f "# ifndef _GLIBCXX_HAVE_SLEEP"
puts $f "# error No nanosleep or sleep"
puts $f "# endif"
puts $f "#endif" puts $f "#endif"
close $f close $f
...@@ -1399,13 +1401,13 @@ proc check_v3_target_nanosleep { } { ...@@ -1399,13 +1401,13 @@ proc check_v3_target_nanosleep { } {
if [string match "" $lines] { if [string match "" $lines] {
# No error message, preprocessing succeeded. # No error message, preprocessing succeeded.
set et_nanosleep 1 set et_sleep 1
} else { } else {
verbose "check_v3_target_nanosleep: compilation failed" 2 verbose "check_v3_target_sleep: compilation failed" 2
} }
} }
verbose "check_v3_target_nanosleep: $et_nanosleep" 2 verbose "check_v3_target_sleep: $et_sleep" 2
return $et_nanosleep return $et_sleep
} }
proc check_v3_target_sched_yield { } { proc check_v3_target_sched_yield { } {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment