From 43653c334ddade011be1670ccdeac12b9f47e26e Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Sat, 28 May 2011 17:27:01 +0000 Subject: [PATCH] acinclude.m4: Define GLIBCXX_CHECK_GET_NPROCS and GLIBCXX_CHECK_SC_NPROCESSORS_ONLN. 2011-05-28 Jonathan Wakely * acinclude.m4: Define GLIBCXX_CHECK_GET_NPROCS and GLIBCXX_CHECK_SC_NPROCESSORS_ONLN. * configure.ac: Use them. Increase minor version. * configure: Regenerate. * config.h.in: Regenerate. * include/std/thread (thread::hardware_concurrency): Remove inline definition. * src/thread.cc (thread::hardware_concurrency): Define. * config/abi/pre/gnu.ver: Export new symbol @3.4.17 * testsuite/util/testsuite_abi.cc: Add new version. * testsuite/lib/libstdc++.exp (check_v3_target_nprocs): Add. * testsuite/lib/dg-options.exp (dg-require-nprocs): Add. * testsuite/30_threads/thread/members/hardware_concurrency.cc: Use dg-require-nprocs and verify hardware_concurrency returns non-zero. From-SVN: r174383 --- libstdc++-v3/ChangeLog | 17 ++ libstdc++-v3/acinclude.m4 | 55 ++++++ libstdc++-v3/config.h.in | 9 + libstdc++-v3/config/abi/pre/gnu.ver | 7 + libstdc++-v3/configure | 184 +++++++++++++++++- libstdc++-v3/configure.ac | 8 +- libstdc++-v3/include/std/thread | 3 +- libstdc++-v3/src/thread.cc | 19 ++ .../thread/members/hardware_concurrency.cc | 6 +- libstdc++-v3/testsuite/lib/dg-options.exp | 9 + libstdc++-v3/testsuite/lib/libstdc++.exp | 63 ++++++ libstdc++-v3/testsuite/util/testsuite_abi.cc | 1 + 12 files changed, 374 insertions(+), 7 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 6d6d5014231..393b728e470 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,20 @@ +2011-05-28 Jonathan Wakely + + * acinclude.m4: Define GLIBCXX_CHECK_GET_NPROCS and + GLIBCXX_CHECK_SC_NPROCESSORS_ONLN. + * configure.ac: Use them. Increase minor version. + * configure: Regenerate. + * config.h.in: Regenerate. + * include/std/thread (thread::hardware_concurrency): Remove inline + definition. + * src/thread.cc (thread::hardware_concurrency): Define. + * config/abi/pre/gnu.ver: Export new symbol @3.4.17 + * testsuite/util/testsuite_abi.cc: Add new version. + * testsuite/lib/libstdc++.exp (check_v3_target_nprocs): Add. + * testsuite/lib/dg-options.exp (dg-require-nprocs): Add. + * testsuite/30_threads/thread/members/hardware_concurrency.cc: Use + dg-require-nprocs and verify hardware_concurrency returns non-zero. + 2011-05-28 Jonathan Wakely * testsuite/20_util/pointer_traits/pointer_to.cc: New. diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4 index ed8b129c29f..bedb585f13f 100644 --- a/libstdc++-v3/acinclude.m4 +++ b/libstdc++-v3/acinclude.m4 @@ -3204,6 +3204,61 @@ AC_DEFUN([AC_LC_MESSAGES], [ ]) ]) +dnl +dnl Check whether get_nprocs is available in , and define _GLIBCXX_USE_GET_NPROCS. +dnl +AC_DEFUN([GLIBCXX_CHECK_GET_NPROCS], [ + + AC_LANG_SAVE + AC_LANG_CPLUSPLUS + ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS -fno-exceptions" + + AC_MSG_CHECKING([for get_nprocs]) + AC_CACHE_VAL(glibcxx_cv_GET_NPROCS, [ + GCC_TRY_COMPILE_OR_LINK( + [#include ], + [int n = get_nprocs();], + [glibcxx_cv_GET_NPROCS=yes], + [glibcxx_cv_GET_NPROCS=no]) + ]) + if test $glibcxx_cv_GET_NPROCS = yes; then + AC_DEFINE(_GLIBCXX_USE_GET_NPROCS, 1, [Define if get_nprocs is available in .]) + fi + AC_MSG_RESULT($glibcxx_cv_GET_NPROCS) + + CXXFLAGS="$ac_save_CXXFLAGS" + AC_LANG_RESTORE +]) + +dnl +dnl Check whether sysconf(_SC_NPROCESSORS_ONLN) is available in , and define _GLIBCXX_USE_SC_NPROCESSORS_ONLN. +dnl +AC_DEFUN([GLIBCXX_CHECK_SC_NPROCESSORS_ONLN], [ + + AC_LANG_SAVE + AC_LANG_CPLUSPLUS + ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS -fno-exceptions" + + AC_MSG_CHECKING([for _SC_NPROCESSORS_ONLN]) + AC_CACHE_VAL(glibcxx_cv_SC_NPROCESSORS_ONLN, [ + GCC_TRY_COMPILE_OR_LINK( + [#include ], + [int n = sysconf(_SC_NPROCESSORS_ONLN);], + [glibcxx_cv_SC_NPROCESSORS_ONLN=yes], + [glibcxx_cv_SC_NPROCESSORS_ONLN=no]) + ]) + if test $glibcxx_cv_SC_NPROCESSORS_ONLN = yes; then + AC_DEFINE(_GLIBCXX_USE_SC_NPROCESSORS_ONLN, 1, [Define if _SC_NPROCESSORS_ONLN is available in .]) + fi + AC_MSG_RESULT($glibcxx_cv_SC_NPROCESSORS_ONLN) + + CXXFLAGS="$ac_save_CXXFLAGS" + AC_LANG_RESTORE +]) + + # Macros from the top-level gcc directory. m4_include([../config/gc++filt.m4]) m4_include([../config/tls.m4]) diff --git a/libstdc++-v3/config.h.in b/libstdc++-v3/config.h.in index 6ab257fa344..6137ba02827 100644 --- a/libstdc++-v3/config.h.in +++ b/libstdc++-v3/config.h.in @@ -380,6 +380,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_SYS_STAT_H +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_SYSINFO_H + /* Define to 1 if you have the header file. */ #undef HAVE_SYS_TIME_H @@ -792,6 +795,9 @@ /* Defined if gettimeofday is available. */ #undef _GLIBCXX_USE_GETTIMEOFDAY +/* Define if get_nprocs is available in . */ +#undef _GLIBCXX_USE_GET_NPROCS + /* Define if LFS support is available. */ #undef _GLIBCXX_USE_LFS @@ -811,6 +817,9 @@ /* Defined if sched_yield is available. */ #undef _GLIBCXX_USE_SCHED_YIELD +/* Define if _SC_NPROCESSORS_ONLN is available in . */ +#undef _GLIBCXX_USE_SC_NPROCESSORS_ONLN + /* Define if code specialized for wchar_t should be used. */ #undef _GLIBCXX_USE_WCHAR_T diff --git a/libstdc++-v3/config/abi/pre/gnu.ver b/libstdc++-v3/config/abi/pre/gnu.ver index 57744a410e5..427189c063d 100644 --- a/libstdc++-v3/config/abi/pre/gnu.ver +++ b/libstdc++-v3/config/abi/pre/gnu.ver @@ -1279,6 +1279,13 @@ GLIBCXX_3.4.16 { } GLIBCXX_3.4.15; +GLIBCXX_3.4.17 { + + # std::thread::hardware_concurrency + _ZNSt6thread20hardware_concurrencyEv; + +} GLIBCXX_3.4.16; + # Symbols in the support library (libsupc++) have their own tag. CXXABI_1.3 { diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure index c3cd3a68f81..8f871114b67 100755 --- a/libstdc++-v3/configure +++ b/libstdc++-v3/configure @@ -2825,7 +2825,7 @@ ac_config_headers="$ac_config_headers config.h" ### am handles this now? ORIGINAL_LD_FOR_MULTILIBS=$LD # For libtool versioning info, format is CURRENT:REVISION:AGE -libtool_VERSION=6:16:0 +libtool_VERSION=6:17:0 # Find the rest of the source tree framework. @@ -19521,6 +19521,188 @@ fi +# For hardware_concurrency +for ac_header in sys/sysinfo.h +do : + ac_fn_c_check_header_mongrel "$LINENO" "sys/sysinfo.h" "ac_cv_header_sys_sysinfo_h" "$ac_includes_default" +if test "x$ac_cv_header_sys_sysinfo_h" = x""yes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_SYS_SYSINFO_H 1 +_ACEOF + +fi + +done + + + + + ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + + ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS -fno-exceptions" + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for get_nprocs" >&5 +$as_echo_n "checking for get_nprocs... " >&6; } + if test "${glibcxx_cv_GET_NPROCS+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + + if test x$gcc_no_link = xyes; then + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +int n = get_nprocs(); + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + glibcxx_cv_GET_NPROCS=yes +else + glibcxx_cv_GET_NPROCS=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +else + if test x$gcc_no_link = xyes; then + as_fn_error "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5 +fi +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +int n = get_nprocs(); + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_link "$LINENO"; then : + glibcxx_cv_GET_NPROCS=yes +else + glibcxx_cv_GET_NPROCS=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi + +fi + + if test $glibcxx_cv_GET_NPROCS = yes; then + +$as_echo "#define _GLIBCXX_USE_GET_NPROCS 1" >>confdefs.h + + fi + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $glibcxx_cv_GET_NPROCS" >&5 +$as_echo "$glibcxx_cv_GET_NPROCS" >&6; } + + CXXFLAGS="$ac_save_CXXFLAGS" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +for ac_header in unistd.h +do : + ac_fn_c_check_header_mongrel "$LINENO" "unistd.h" "ac_cv_header_unistd_h" "$ac_includes_default" +if test "x$ac_cv_header_unistd_h" = x""yes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_UNISTD_H 1 +_ACEOF + +fi + +done + + + + + ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + + ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS -fno-exceptions" + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for _SC_NPROCESSORS_ONLN" >&5 +$as_echo_n "checking for _SC_NPROCESSORS_ONLN... " >&6; } + if test "${glibcxx_cv_SC_NPROCESSORS_ONLN+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + + if test x$gcc_no_link = xyes; then + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +int n = sysconf(_SC_NPROCESSORS_ONLN); + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + glibcxx_cv_SC_NPROCESSORS_ONLN=yes +else + glibcxx_cv_SC_NPROCESSORS_ONLN=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +else + if test x$gcc_no_link = xyes; then + as_fn_error "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5 +fi +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +int n = sysconf(_SC_NPROCESSORS_ONLN); + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_link "$LINENO"; then : + glibcxx_cv_SC_NPROCESSORS_ONLN=yes +else + glibcxx_cv_SC_NPROCESSORS_ONLN=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi + +fi + + if test $glibcxx_cv_SC_NPROCESSORS_ONLN = yes; then + +$as_echo "#define _GLIBCXX_USE_SC_NPROCESSORS_ONLN 1" >>confdefs.h + + fi + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $glibcxx_cv_SC_NPROCESSORS_ONLN" >&5 +$as_echo "$glibcxx_cv_SC_NPROCESSORS_ONLN" >&6; } + + CXXFLAGS="$ac_save_CXXFLAGS" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + # Check for available headers. for ac_header in endian.h execinfo.h float.h fp.h ieeefp.h inttypes.h \ locale.h machine/endian.h machine/param.h nan.h stdint.h stdlib.h string.h \ diff --git a/libstdc++-v3/configure.ac b/libstdc++-v3/configure.ac index 35c54fd4e9a..416c0d72d68 100644 --- a/libstdc++-v3/configure.ac +++ b/libstdc++-v3/configure.ac @@ -12,7 +12,7 @@ AC_CONFIG_HEADER(config.h) ### am handles this now? ORIGINAL_LD_FOR_MULTILIBS=$LD # For libtool versioning info, format is CURRENT:REVISION:AGE -libtool_VERSION=6:16:0 +libtool_VERSION=6:17:0 AC_SUBST(libtool_VERSION) # Find the rest of the source tree framework. @@ -170,6 +170,12 @@ GLIBCXX_CHECK_GTHREADS AC_LC_MESSAGES +# For hardware_concurrency +AC_CHECK_HEADERS(sys/sysinfo.h) +GLIBCXX_CHECK_GET_NPROCS +AC_CHECK_HEADERS(unistd.h) +GLIBCXX_CHECK_SC_NPROCESSORS_ONLN + # Check for available headers. AC_CHECK_HEADERS([endian.h execinfo.h float.h fp.h ieeefp.h inttypes.h \ locale.h machine/endian.h machine/param.h nan.h stdint.h stdlib.h string.h \ diff --git a/libstdc++-v3/include/std/thread b/libstdc++-v3/include/std/thread index e7a9b14276f..ab85735154e 100644 --- a/libstdc++-v3/include/std/thread +++ b/libstdc++-v3/include/std/thread @@ -179,8 +179,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Returns a value that hints at the number of hardware thread contexts. static unsigned int - hardware_concurrency() noexcept - { return 0; } + hardware_concurrency() noexcept; private: void diff --git a/libstdc++-v3/src/thread.cc b/libstdc++-v3/src/thread.cc index c164e8a0161..cc23c19768f 100644 --- a/libstdc++-v3/src/thread.cc +++ b/libstdc++-v3/src/thread.cc @@ -26,6 +26,16 @@ #include #include +#if defined(_GLIBCXX_USE_GET_NPROCS) +# include +# define _GLIBCXX_NPROCS get_nprocs() +#elif defined(_GLIBCXX_USE_SC_NPROCESSORS_ONLN) +# include +# define _GLIBCXX_NPROCS sysconf(_SC_NPROCESSORS_ONLN) +#else +# define _GLIBCXX_NPROCS 0 +#endif + #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1) namespace std _GLIBCXX_VISIBILITY(default) @@ -98,6 +108,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } } + unsigned int + thread::hardware_concurrency() noexcept + { + int __n = _GLIBCXX_NPROCS; + if (__n < 0) + __n = 0; + return __n; + } + _GLIBCXX_END_NAMESPACE_VERSION } // namespace std diff --git a/libstdc++-v3/testsuite/30_threads/thread/members/hardware_concurrency.cc b/libstdc++-v3/testsuite/30_threads/thread/members/hardware_concurrency.cc index c2917ca6f1c..51d024dacdb 100644 --- a/libstdc++-v3/testsuite/30_threads/thread/members/hardware_concurrency.cc +++ b/libstdc++-v3/testsuite/30_threads/thread/members/hardware_concurrency.cc @@ -4,8 +4,9 @@ // { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } } // { dg-require-cstdint "" } // { dg-require-gthreads "" } +// { dg-require-nprocs "" } -// Copyright (C) 2009 Free Software Foundation, Inc. +// Copyright (C) 2009, 2010, 2011 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 @@ -29,8 +30,7 @@ int main() { bool test __attribute__((unused)) = true; - // Current implementation punts on this. - VERIFY( std::thread::hardware_concurrency() == 0 ); + VERIFY( std::thread::hardware_concurrency() >= 1 ); return 0; } diff --git a/libstdc++-v3/testsuite/lib/dg-options.exp b/libstdc++-v3/testsuite/lib/dg-options.exp index 43695f01b1c..46d3ce9e71a 100644 --- a/libstdc++-v3/testsuite/lib/dg-options.exp +++ b/libstdc++-v3/testsuite/lib/dg-options.exp @@ -179,6 +179,15 @@ proc dg-require-binary-io { args } { return } +proc dg-require-nprocs { args } { + if { ![ check_v3_target_nprocs ] } { + upvar dg-do-what dg-do-what + set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"] + return + } + return +} + proc add_options_for_no_pch { flags } { # This forces any generated and possibly included PCH to be invalid. return "-D__GLIBCXX__=99999999" diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp b/libstdc++-v3/testsuite/lib/libstdc++.exp index 151c9422f0c..d39e8ea182c 100644 --- a/libstdc++-v3/testsuite/lib/libstdc++.exp +++ b/libstdc++-v3/testsuite/lib/libstdc++.exp @@ -1579,4 +1579,67 @@ proc check_v3_target_binary_io { } { return $et_binary_io } +proc check_v3_target_nprocs { } { + global cxxflags + global DEFAULT_CXXFLAGS + global et_nprocs + + global tool + + if { ![info exists et_nprocs_target_name] } { + set et_nprocs_target_name "" + } + + # If the target has changed since we set the cached value, clear it. + set current_target [current_target_name] + if { $current_target != $et_nprocs_target_name } { + verbose "check_v3_target_nprocs: `$et_nprocs_target_name'" 2 + set et_nprocs_target_name $current_target + if [info exists et_nprocs] { + verbose "check_v3_target_nprocs: removing cached result" 2 + unset et_nprocs + } + } + + if [info exists et_nprocs] { + verbose "check_v3_target_nprocs: using cached result" 2 + } else { + set et_nprocs 0 + + # Set up and preprocess a C++0x test program that depends + # on either get_nprocs or sysconf to be available. + set src nprocs[pid].cc + + set f [open $src "w"] + puts $f "#include " + puts $f "#if defined(_GLIBCXX_USE_GET_NPROCS)" + puts $f "#elif defined(_GLIBCXX_USE_SYSCONF)" + puts $f "# include " + puts $f "# if !defined(_SC_NPROCESSORS_ONLN)" + puts $f "# error No sysconf option" + puts $f "# endif" + puts $f "#else" + puts $f "# error No get_nprocs or sysconf" + puts $f "#endif" + close $f + + set cxxflags_saved $cxxflags + set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror" + + set lines [v3_target_compile $src /dev/null preprocess ""] + set cxxflags $cxxflags_saved + file delete $src + + if [string match "" $lines] { + # No error message, preprocess succeeded. + set et_nprocs 1 + } else { + verbose "check_v3_target_nprocs: compilation failed" 2 + } + } + verbose "check_v3_target_nprocs: $et_nprocs" 2 + return $et_nprocs +} + + set additional_prunes "" diff --git a/libstdc++-v3/testsuite/util/testsuite_abi.cc b/libstdc++-v3/testsuite/util/testsuite_abi.cc index ea100b6817f..f1f5ad66347 100644 --- a/libstdc++-v3/testsuite/util/testsuite_abi.cc +++ b/libstdc++-v3/testsuite/util/testsuite_abi.cc @@ -194,6 +194,7 @@ check_version(symbol& test, bool added) known_versions.push_back("GLIBCXX_3.4.14"); known_versions.push_back("GLIBCXX_3.4.15"); known_versions.push_back("GLIBCXX_3.4.16"); + known_versions.push_back("GLIBCXX_3.4.17"); known_versions.push_back("GLIBCXX_LDBL_3.4"); known_versions.push_back("GLIBCXX_LDBL_3.4.7"); known_versions.push_back("GLIBCXX_LDBL_3.4.10"); -- 2.30.2