Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions nob.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,19 @@
# include <io.h>
# include <shellapi.h>
#else
# ifdef __APPLE__
# include <mach-o/dyld.h>
# if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
# ifndef __BSD_VISIBLE
# define __BSD_VISIBLE 1
# endif
# endif
# ifdef __FreeBSD__
# include <sys/types.h>
# if defined(__FreeBSD__)
# include <sys/param.h>
# include <sys/sysctl.h>
# endif
# include <sys/types.h>
# ifdef __APPLE__
# include <mach-o/dyld.h>
# endif
# include <sys/wait.h>
# include <sys/stat.h>
# include <unistd.h>
Expand Down Expand Up @@ -1293,7 +1299,31 @@ NOBDEF int nob_nprocs(void)
GetSystemInfo(&siSysInfo);
return siSysInfo.dwNumberOfProcessors;
#else
return sysconf(_SC_NPROCESSORS_ONLN);
#ifdef _SC_NPROCESSORS_ONLN
{
long n = sysconf(_SC_NPROCESSORS_ONLN);
if (n > 0) return (int)n;
}
#endif
#if defined(__FreeBSD__)
{
#if defined(CTL_HW) && defined(HW_NCPU)
int mib[2] = {CTL_HW, HW_NCPU};
int ncpu = 0;
size_t len = sizeof(ncpu);
if (sysctl(mib, 2, &ncpu, &len, NULL, 0) == 0 && ncpu > 0)
return ncpu;
#endif
{
int ncpu = 0;
size_t len = sizeof(ncpu);
if (sysctlbyname("hw.ncpu", &ncpu, &len, NULL, 0) == 0 &&
ncpu > 0)
return ncpu;
}
}
#endif
return 1;
#endif
}

Expand Down