[cfe-dev] [libcxx] Why is <sys/sysctl.h> included by default?

David Chisnall via cfe-dev cfe-dev at lists.llvm.org
Tue Jan 26 01:34:42 PST 2016


On 25 Jan 2016, at 21:13, Craig, Ben via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> 
> So if your OS is not one of the six listed (_WIN21, __sun__, __linux__, AIX, __native_client__, __CloudABI__), then you get to include sys/sysctl.h.  sysctl.h isn't defined by the standard C library, and isn't part of POSIX.
> 
> I'm trying to add some new embedded OS and C library support to libcxx, and I don't have a sys/sysctl.h.  I think the correct and maintainable thing to do here is to switch away from black-listing certain OSes, and instead white-list the OSes that want to use sys/sysctl.h here.  I don't know what that list is though.

That list is anything BSD-derived (FreeBSD, NetBSD, OpenBSD, DragonFlyBSD, iOS, OS X, at least, so a similar length list to the blacklist currently).  

That said, it looks as if sysctl is only used in thread::hardware_concurrency() though, and there’s a fallback path using sysconf, which should be portable to all vaguely *NIX-like platforms.  The fallback path works at least on OS X, FreeBSD, and Linux (and presumably Dragonfly, as I believe this code predates their fork), so probably makes more sense.  I don’t know if any other BSDs fail to implement sysconf(_SC_NPROCESSORS_ONLN), but that code path may actually be dead.


David




More information about the cfe-dev mailing list