[libcxx-commits] [PATCH] D92135: [libc++] Remove sysctl-based implementation of thread::hardware_concurrency()
Louis Dionne via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Nov 25 13:55:04 PST 2020
ldionne created this revision.
Herald added subscribers: libcxx-commits, jkorous.
Herald added a project: libc++.
Herald added a reviewer: libc++.
ldionne requested review of this revision.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D92135
Files:
libcxx/src/thread.cpp
Index: libcxx/src/thread.cpp
===================================================================
--- libcxx/src/thread.cpp
+++ libcxx/src/thread.cpp
@@ -15,20 +15,8 @@
#include "future"
#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>)
-# include <unistd.h>
+# include <unistd.h> // for sysconf
#endif
#if defined(__NetBSD__)
@@ -84,13 +72,7 @@
unsigned
thread::hardware_concurrency() _NOEXCEPT
{
-#if defined(CTL_HW) && defined(HW_NCPU)
- 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)
+#if 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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92135.307713.patch
Type: text/x-patch
Size: 1035 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20201125/33bc3ed0/attachment.bin>
More information about the libcxx-commits
mailing list