forked from OSchip/llvm-project
[libc++] Remove sysctl-based implementation of thread::hardware_concurrency()
Using sysctl requires including headers that are considered internal on Linux, like <sys/sysctl.h> & friends. Instead, sysconf is defined by POSIX (and we have a fallback for Windows), so all the systems we support should be happy with just sysconf. Differential Revision: https://reviews.llvm.org/D92135
This commit is contained in:
parent
d7ca140c01
commit
3d7f19ff18
|
@ -15,20 +15,8 @@
|
||||||
#include "future"
|
#include "future"
|
||||||
#include "limits"
|
#include "limits"
|
||||||
|
|
||||||
#if __has_include(<sys/types.h>)
|
|
||||||
# include <sys/types.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if __has_include(<sys/param.h>)
|
|
||||||
# include <sys/param.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if __has_include(<sys/sysctl.h>)
|
|
||||||
# include <sys/sysctl.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if __has_include(<unistd.h>)
|
#if __has_include(<unistd.h>)
|
||||||
# include <unistd.h>
|
# include <unistd.h> // for sysconf
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__NetBSD__)
|
#if defined(__NetBSD__)
|
||||||
|
@ -84,13 +72,7 @@ thread::detach()
|
||||||
unsigned
|
unsigned
|
||||||
thread::hardware_concurrency() _NOEXCEPT
|
thread::hardware_concurrency() _NOEXCEPT
|
||||||
{
|
{
|
||||||
#if defined(CTL_HW) && defined(HW_NCPU)
|
#if defined(_SC_NPROCESSORS_ONLN)
|
||||||
unsigned n;
|
|
||||||
int mib[2] = {CTL_HW, HW_NCPU};
|
|
||||||
std::size_t s = sizeof(n);
|
|
||||||
sysctl(mib, 2, &n, &s, 0, 0);
|
|
||||||
return n;
|
|
||||||
#elif defined(_SC_NPROCESSORS_ONLN)
|
|
||||||
long result = sysconf(_SC_NPROCESSORS_ONLN);
|
long result = sysconf(_SC_NPROCESSORS_ONLN);
|
||||||
// sysconf returns -1 if the name is invalid, the option does not exist or
|
// sysconf returns -1 if the name is invalid, the option does not exist or
|
||||||
// does not have a definite limit.
|
// does not have a definite limit.
|
||||||
|
|
Loading…
Reference in New Issue