diff options
author | Howard Hinnant <hhinnant@apple.com> | 2012-08-02 18:17:49 +0000 |
---|---|---|
committer | Howard Hinnant <hhinnant@apple.com> | 2012-08-02 18:17:49 +0000 |
commit | d3673eb4e1716bd727e4bae276bc2798afe3c7c0 (patch) | |
tree | 888f01a37ec78a5790cefddd633a1757650d5eb9 | |
parent | fffad897f20a68913e4fbbfd1f86ce8fc1a16d62 (diff) | |
download | bcm5719-llvm-d3673eb4e1716bd727e4bae276bc2798afe3c7c0.tar.gz bcm5719-llvm-d3673eb4e1716bd727e4bae276bc2798afe3c7c0.zip |
Andrew Morrow: The attached patch is an attempt to implement
std::thread::hardware_concurrency for platforms that don't offer
sysctl, but do provide a POSIX sysconf and _SC_NPROCESSORS_ONLN.
llvm-svn: 161190
-rw-r--r-- | libcxx/src/thread.cpp | 13 | ||||
-rw-r--r-- | libcxx/www/results.Linux.html | 7 |
2 files changed, 11 insertions, 9 deletions
diff --git a/libcxx/src/thread.cpp b/libcxx/src/thread.cpp index ffcbe0ab667..4445b8dbb9c 100644 --- a/libcxx/src/thread.cpp +++ b/libcxx/src/thread.cpp @@ -12,9 +12,13 @@ #include "vector" #include "future" #include <sys/types.h> -#if !_WIN32 && !__sun__ +#if !_WIN32 +#if !__sun__ && !__linux__ #include <sys/sysctl.h> -#endif // _WIN32 +#else +#include <unistd.h> +#endif // !__sun__ && !__linux__ +#endif // !_WIN32 _LIBCPP_BEGIN_NAMESPACE_STD @@ -60,6 +64,11 @@ thread::hardware_concurrency() _NOEXCEPT std::size_t s = sizeof(n); sysctl(mib, 2, &n, &s, 0, 0); return n; +#elif defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L) && defined(_SC_NPROCESSORS_ONLN) + long result = sysconf(_SC_NPROCESSORS_ONLN); + if (result < 0 || result > UINT_MAX) + result = 0; + return result; #else // defined(CTL_HW) && defined(HW_NCPU) // TODO: grovel through /proc or check cpuid on x86 and similar // instructions on other architectures. diff --git a/libcxx/www/results.Linux.html b/libcxx/www/results.Linux.html index ddecb0a0401..9161dce9d52 100644 --- a/libcxx/www/results.Linux.html +++ b/libcxx/www/results.Linux.html @@ -113,13 +113,6 @@ strings/ c.strings/ cuchar.pass.cpp: Can't find cuchar header version_cuchar.pass.cpp: idem. -thread/ - thread.threads/ - thread.thread.class/ - thread.thread.static/ - hardware_concurrency.pass.cpp: Fails due to - std::hardware_concurrency unimplemented for non-BSD - systems. Patch in progress. utilities/ memory/ unique.ptr/ |