diff options
author | redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-11-07 13:45:03 +0000 |
---|---|---|
committer | redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-11-07 13:45:03 +0000 |
commit | da22c41abba8c6d2fddbe78b50f2343f9f1cc79c (patch) | |
tree | 461e6e015d8436bcc9d9a9eb507a084852127558 /libstdc++-v3 | |
parent | 714ddaba8928b6af77f148c4744100b09426ae43 (diff) | |
download | gcc-da22c41abba8c6d2fddbe78b50f2343f9f1cc79c.tar.gz |
* acinclude.m4 (GLIBCXX_CHECK_SC_NPROC_ONLN): Define.
(GLIBCXX_CHECK_PTHREADS_NUM_PROCESSORS_NP): Define.
(GLIBCXX_CHECK_SYSCTL_HW_NCPU): Define.
* configure.ac: Use new checks.
* configure: Regenerate.
* config.h.in: Regenerate.
* src/thread.cc: Check new config macros.
* testsuite/lib/libstdc++.exp: Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@181084 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3')
-rw-r--r-- | libstdc++-v3/ChangeLog | 11 | ||||
-rw-r--r-- | libstdc++-v3/acinclude.m4 | 88 | ||||
-rw-r--r-- | libstdc++-v3/config.h.in | 9 | ||||
-rwxr-xr-x | libstdc++-v3/configure | 250 | ||||
-rw-r--r-- | libstdc++-v3/configure.ac | 3 | ||||
-rw-r--r-- | libstdc++-v3/src/thread.cc | 18 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/lib/libstdc++.exp | 11 |
7 files changed, 384 insertions, 6 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index f619177c01e..2e5ccf0ecfc 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,16 @@ 2011-11-07 Jonathan Wakely <jwakely.gcc@gmail.com> + * acinclude.m4 (GLIBCXX_CHECK_SC_NPROC_ONLN): Define. + (GLIBCXX_CHECK_PTHREADS_NUM_PROCESSORS_NP): Define. + (GLIBCXX_CHECK_SYSCTL_HW_NCPU): Define. + * configure.ac: Use new checks. + * configure: Regenerate. + * config.h.in: Regenerate. + * src/thread.cc: Check new config macros. + * testsuite/lib/libstdc++.exp: Likewise. + +2011-11-07 Jonathan Wakely <jwakely.gcc@gmail.com> + * config/abi/pre/gnu.ver: Fix exports for string::pop_back. 2011-11-07 Jonathan Wakely <jwakely.gcc@gmail.com> diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4 index 3464b76b79c..6cc6ace873f 100644 --- a/libstdc++-v3/acinclude.m4 +++ b/libstdc++-v3/acinclude.m4 @@ -3459,6 +3459,94 @@ AC_DEFUN([GLIBCXX_CHECK_SC_NPROCESSORS_ONLN], [ AC_LANG_RESTORE ]) +dnl +dnl Check whether sysconf(_SC_NPROC_ONLN) is available in <unistd.h>, and define _GLIBCXX_USE_SC_NPROC_ONLN. +dnl +AC_DEFUN([GLIBCXX_CHECK_SC_NPROC_ONLN], [ + + AC_LANG_SAVE + AC_LANG_CPLUSPLUS + ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS -fno-exceptions" + + AC_MSG_CHECKING([for _SC_NPROC_ONLN]) + AC_CACHE_VAL(glibcxx_cv_SC_NPROC_ONLN, [ + GCC_TRY_COMPILE_OR_LINK( + [#include <unistd.h>], + [int n = sysconf(_SC_NPROC_ONLN);], + [glibcxx_cv_SC_NPROC_ONLN=yes], + [glibcxx_cv_SC_NPROC_ONLN=no]) + ]) + if test $glibcxx_cv_SC_NPROC_ONLN = yes; then + AC_DEFINE(_GLIBCXX_USE_SC_NPROC_ONLN, 1, [Define if _SC_NPROC_ONLN is available in <unistd.h>.]) + fi + AC_MSG_RESULT($glibcxx_cv_SC_NPROC_ONLN) + + CXXFLAGS="$ac_save_CXXFLAGS" + AC_LANG_RESTORE +]) + +dnl +dnl Check whether pthread_num_processors_np is available in <pthread.h>, and define _GLIBCXX_USE_PTHREADS_NUM_PROCESSORS_NP. +dnl +AC_DEFUN([GLIBCXX_CHECK_PTHREADS_NUM_PROCESSORS_NP], [ + + AC_LANG_SAVE + AC_LANG_CPLUSPLUS + ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS -fno-exceptions" + + AC_MSG_CHECKING([for pthreads_num_processors_np]) + AC_CACHE_VAL(glibcxx_cv_PTHREADS_NUM_PROCESSORS_NP, [ + GCC_TRY_COMPILE_OR_LINK( + [#include <pthread.h>], + [int n = pthread_num_processors_np();], + [glibcxx_cv_PTHREADS_NUM_PROCESSORS_NP=yes], + [glibcxx_cv_PTHREADS_NUM_PROCESSORS_NP=no]) + ]) + if test $glibcxx_cv_PTHREADS_NUM_PROCESSORS_NP = yes; then + AC_DEFINE(_GLIBCXX_USE_PTHREADS_NUM_PROCESSORS_NP, 1, [Define if pthreads_num_processors_np is available in <pthread.h>.]) + fi + AC_MSG_RESULT($glibcxx_cv_PTHREADS_NUM_PROCESSORS_NP) + + CXXFLAGS="$ac_save_CXXFLAGS" + AC_LANG_RESTORE +]) + +dnl +dnl Check whether sysctl is available in <pthread.h>, and define _GLIBCXX_USE_SYSCTL_HW_NCPU. +dnl +AC_DEFUN([GLIBCXX_CHECK_SYSCTL_HW_NCPU], [ + + AC_LANG_SAVE + AC_LANG_CPLUSPLUS + ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS -fno-exceptions" + + AC_MSG_CHECKING([for hw.ncpu sysctl]) + AC_CACHE_VAL(glibcxx_cv_SYSCTL_HW_NCPU, [ + GCC_TRY_COMPILE_OR_LINK( + [ + #include <stddef.h> + #include <sys/sysctl.h> + ], + [ + int count; + size_t size = sizeof(count); + int mib[] = { CTL_HW, HW_NCPU }; + sysctl(mib, 2, &count, &size, NULL, 0); + ], + [glibcxx_cv_SYSCTL_HW_NCPU=yes], + [glibcxx_cv_SYSCTL_HW_NCPU=no]) + ]) + if test $glibcxx_cv_SYSCTL_HW_NCPU = yes; then + AC_DEFINE(_GLIBCXX_USE_SYSCTL_HW_NCPU, 1, [Define if sysctl(), CTL_HW and HW_NCPU are available in <sys/sysctl.h>.]) + fi + AC_MSG_RESULT($glibcxx_cv_SYSCTL_HW_NCPU) + + CXXFLAGS="$ac_save_CXXFLAGS" + AC_LANG_RESTORE +]) # Macros from the top-level gcc directory. m4_include([../config/gc++filt.m4]) diff --git a/libstdc++-v3/config.h.in b/libstdc++-v3/config.h.in index 82ccd4e1a9d..7215a7fec62 100644 --- a/libstdc++-v3/config.h.in +++ b/libstdc++-v3/config.h.in @@ -831,6 +831,9 @@ /* Define if NLS translations are to be used. */ #undef _GLIBCXX_USE_NLS +/* Define if pthreads_num_processors_np is available in <pthread.h>. */ +#undef _GLIBCXX_USE_PTHREADS_NUM_PROCESSORS_NP + /* Define if /dev/random and /dev/urandom are available for the random_device of TR1 (Chapter 5.1). */ #undef _GLIBCXX_USE_RANDOM_TR1 @@ -841,6 +844,12 @@ /* Define if _SC_NPROCESSORS_ONLN is available in <unistd.h>. */ #undef _GLIBCXX_USE_SC_NPROCESSORS_ONLN +/* Define if _SC_NPROC_ONLN is available in <unistd.h>. */ +#undef _GLIBCXX_USE_SC_NPROC_ONLN + +/* Define if sysctl(), CTL_HW and HW_NCPU are available in <sys/sysctl.h>. */ +#undef _GLIBCXX_USE_SYSCTL_HW_NCPU + /* Define if code specialized for wchar_t should be used. */ #undef _GLIBCXX_USE_WCHAR_T diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure index 94b29a08a27..3be252e5c85 100755 --- a/libstdc++-v3/configure +++ b/libstdc++-v3/configure @@ -20132,6 +20132,256 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + 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_NPROC_ONLN" >&5 +$as_echo_n "checking for _SC_NPROC_ONLN... " >&6; } + if test "${glibcxx_cv_SC_NPROC_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 <unistd.h> +int +main () +{ +int n = sysconf(_SC_NPROC_ONLN); + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + glibcxx_cv_SC_NPROC_ONLN=yes +else + glibcxx_cv_SC_NPROC_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 <unistd.h> +int +main () +{ +int n = sysconf(_SC_NPROC_ONLN); + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_link "$LINENO"; then : + glibcxx_cv_SC_NPROC_ONLN=yes +else + glibcxx_cv_SC_NPROC_ONLN=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi + +fi + + if test $glibcxx_cv_SC_NPROC_ONLN = yes; then + +$as_echo "#define _GLIBCXX_USE_SC_NPROC_ONLN 1" >>confdefs.h + + fi + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $glibcxx_cv_SC_NPROC_ONLN" >&5 +$as_echo "$glibcxx_cv_SC_NPROC_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 + + + + + + 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 pthreads_num_processors_np" >&5 +$as_echo_n "checking for pthreads_num_processors_np... " >&6; } + if test "${glibcxx_cv_PTHREADS_NUM_PROCESSORS_NP+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 <pthread.h> +int +main () +{ +int n = pthread_num_processors_np(); + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + glibcxx_cv_PTHREADS_NUM_PROCESSORS_NP=yes +else + glibcxx_cv_PTHREADS_NUM_PROCESSORS_NP=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 <pthread.h> +int +main () +{ +int n = pthread_num_processors_np(); + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_link "$LINENO"; then : + glibcxx_cv_PTHREADS_NUM_PROCESSORS_NP=yes +else + glibcxx_cv_PTHREADS_NUM_PROCESSORS_NP=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi + +fi + + if test $glibcxx_cv_PTHREADS_NUM_PROCESSORS_NP = yes; then + +$as_echo "#define _GLIBCXX_USE_PTHREADS_NUM_PROCESSORS_NP 1" >>confdefs.h + + fi + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $glibcxx_cv_PTHREADS_NUM_PROCESSORS_NP" >&5 +$as_echo "$glibcxx_cv_PTHREADS_NUM_PROCESSORS_NP" >&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 + + + + + + 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 hw.ncpu sysctl" >&5 +$as_echo_n "checking for hw.ncpu sysctl... " >&6; } + if test "${glibcxx_cv_SYSCTL_HW_NCPU+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 <stddef.h> + #include <sys/sysctl.h> + +int +main () +{ + + int count; + size_t size = sizeof(count); + int mib[] = { CTL_HW, HW_NCPU }; + sysctl(mib, 2, &count, &size, NULL, 0); + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + glibcxx_cv_SYSCTL_HW_NCPU=yes +else + glibcxx_cv_SYSCTL_HW_NCPU=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 <stddef.h> + #include <sys/sysctl.h> + +int +main () +{ + + int count; + size_t size = sizeof(count); + int mib[] = { CTL_HW, HW_NCPU }; + sysctl(mib, 2, &count, &size, NULL, 0); + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_link "$LINENO"; then : + glibcxx_cv_SYSCTL_HW_NCPU=yes +else + glibcxx_cv_SYSCTL_HW_NCPU=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi + +fi + + if test $glibcxx_cv_SYSCTL_HW_NCPU = yes; then + +$as_echo "#define _GLIBCXX_USE_SYSCTL_HW_NCPU 1" >>confdefs.h + + fi + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $glibcxx_cv_SYSCTL_HW_NCPU" >&5 +$as_echo "$glibcxx_cv_SYSCTL_HW_NCPU" >&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 eb2fe85a7c4..8f853076cbe 100644 --- a/libstdc++-v3/configure.ac +++ b/libstdc++-v3/configure.ac @@ -174,6 +174,9 @@ AC_CHECK_HEADERS(sys/sysinfo.h) GLIBCXX_CHECK_GET_NPROCS AC_CHECK_HEADERS(unistd.h) GLIBCXX_CHECK_SC_NPROCESSORS_ONLN +GLIBCXX_CHECK_SC_NPROC_ONLN +GLIBCXX_CHECK_PTHREADS_NUM_PROCESSORS_NP +GLIBCXX_CHECK_SYSCTL_HW_NCPU # Check for available headers. AC_CHECK_HEADERS([endian.h execinfo.h float.h fp.h ieeefp.h inttypes.h \ diff --git a/libstdc++-v3/src/thread.cc b/libstdc++-v3/src/thread.cc index 09e7fc5909d..ff034b16143 100644 --- a/libstdc++-v3/src/thread.cc +++ b/libstdc++-v3/src/thread.cc @@ -30,9 +30,27 @@ #if defined(_GLIBCXX_USE_GET_NPROCS) # include <sys/sysinfo.h> # define _GLIBCXX_NPROCS get_nprocs() +#elif defined(_GLIBCXX_USE_PTHREADS_NUM_PROCESSORS_NP) +# define _GLIBCXX_NPROCS pthread_num_processors_np() +#elif defined(_GLIBCXX_USE_SYSCTL_HW_NCPU) +# include <stddef.h> +# include <sys/sysctl.h> +static inline int get_nprocs() +{ + int count; + size_t size = sizeof(count); + int mib[] = { CTL_HW, HW_NCPU }; + if (!sysctl(mib, 2, &count, &size, NULL, 0)) + return count; + return 0; +} +# define _GLIBCXX_NPROCS get_nprocs() #elif defined(_GLIBCXX_USE_SC_NPROCESSORS_ONLN) # include <unistd.h> # define _GLIBCXX_NPROCS sysconf(_SC_NPROCESSORS_ONLN) +#elif defined(_GLIBCXX_USE_SC_NPROC_ONLN) +# include <unistd.h> +# define _GLIBCXX_NPROCS sysconf(_SC_NPROC_ONLN) #else # define _GLIBCXX_NPROCS 0 #endif diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp b/libstdc++-v3/testsuite/lib/libstdc++.exp index b510c06126f..e4191925546 100644 --- a/libstdc++-v3/testsuite/lib/libstdc++.exp +++ b/libstdc++-v3/testsuite/lib/libstdc++.exp @@ -1673,13 +1673,12 @@ proc check_v3_target_nprocs { } { set f [open $src "w"] puts $f "#include <bits/c++config.h>" puts $f "#if defined(_GLIBCXX_USE_GET_NPROCS)" - puts $f "#elif defined(_GLIBCXX_USE_SYSCONF)" - puts $f "# include <unistd.h>" - puts $f "# if !defined(_SC_NPROCESSORS_ONLN)" - puts $f "# error No sysconf option" - puts $f "# endif" + puts $f "#elif defined(_GLIBCXX_USE_PTHREADS_NUM_PROCESSORS_NP)" + puts $f "#elif defined(_GLIBCXX_USE_SYSCTL_HW_NCPU)" + puts $f "#elif defined(_GLIBCXX_USE_SC_NPROCESSORS_ONLN)" + puts $f "#elif defined(_GLIBCXX_USE_SC_NPROC_ONLN)" puts $f "#else" - puts $f "# error No get_nprocs or sysconf" + puts $f "# error hardware_concurrency not implemented" puts $f "#endif" close $f |