mirror of
https://github.com/darlinghq/darling-libcxx.git
synced 2024-12-11 13:47:01 +00:00
Matthew Dempsky: POSIX defines that the _POSIX_C_SOURCE macros are to be set by user
code to specify what version of POSIX the system should provide. If you want to check what version of POSIX is actually available, you're supposed to test _POSIX_VERSION. However, since sysconf() has been in POSIX since 1995, it's probably safe to assume it's available on any system with a C++11 compiler, especially if _SC_NPROCESSORS_ONLN is defined too. So no point in a complicated preprocessor rule if just we unconditionally include <unistd.h> (on non-Windows systems). Also, I've added a #warning for to help porters detect when a suitable implementation isn't detected at compile-time. Howard: Matthew, can you patch CREDITS.TXT? Thanks. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@185275 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
09ca5d49e1
commit
312926eed4
@ -16,9 +16,8 @@
|
||||
#if !defined(_WIN32)
|
||||
#if !defined(__sun__) && !defined(__linux__)
|
||||
#include <sys/sysctl.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif // !__sun__ && !__linux__
|
||||
#include <unistd.h>
|
||||
#endif // !_WIN32
|
||||
|
||||
#if defined(__NetBSD__)
|
||||
@ -71,7 +70,7 @@ 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)) || defined(EMSCRIPTEN)
|
||||
#elif defined(_SC_NPROCESSORS_ONLN)
|
||||
long result = sysconf(_SC_NPROCESSORS_ONLN);
|
||||
// sysconf returns -1 if the name is invalid, the option does not exist or
|
||||
// does not have a definite limit.
|
||||
@ -83,6 +82,7 @@ thread::hardware_concurrency() _NOEXCEPT
|
||||
#else // defined(CTL_HW) && defined(HW_NCPU)
|
||||
// TODO: grovel through /proc or check cpuid on x86 and similar
|
||||
// instructions on other architectures.
|
||||
#warning hardware_concurrency not yet implemented
|
||||
return 0; // Means not computable [thread.thread.static]
|
||||
#endif // defined(CTL_HW) && defined(HW_NCPU)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user