Skip to content

Commit 99ef1f8

Browse files
authored
Merge pull request #18003 from JuliaLang/jn/14874
Remove nonstandard header sys/sysctl.h when unneeded
2 parents c48d203 + bee4f31 commit 99ef1f8

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/sys.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,23 @@
1010
#include <stdlib.h>
1111
#include <string.h>
1212
#include <assert.h>
13+
#include <errno.h>
14+
#include <signal.h>
15+
#include <fcntl.h>
16+
1317
#ifdef _OS_WINDOWS_
1418
#include <psapi.h>
1519
#else
20+
#include <unistd.h>
21+
#if !defined(_SC_NPROCESSORS_ONLN) || defined(_OS_FREEBSD_) || defined(_OS_DARWIN_)
22+
// try secondary location for _SC_NPROCESSORS_ONLN, or for HW_AVAILCPU on BSDs
1623
#include <sys/sysctl.h>
24+
#endif
1725
#include <sys/wait.h>
1826
#include <sys/ptrace.h>
19-
#include <unistd.h>
2027
#include <sys/mman.h>
2128
#include <dlfcn.h>
2229
#endif
23-
#include <errno.h>
24-
#include <signal.h>
25-
#include <fcntl.h>
2630

2731
#ifndef _OS_WINDOWS_
2832
// for getrusage
@@ -355,7 +359,10 @@ JL_DLLEXPORT int jl_cpu_cores(void)
355359
}
356360
return count;
357361
#elif defined(_SC_NPROCESSORS_ONLN)
358-
return sysconf(_SC_NPROCESSORS_ONLN);
362+
long count = sysconf(_SC_NPROCESSORS_ONLN);
363+
if (count < 1)
364+
return 1;
365+
return count;
359366
#elif defined(_OS_WINDOWS_)
360367
//Try to get WIN7 API method
361368
GAPC gapc = (GAPC) jl_dlsym_e(
@@ -372,6 +379,7 @@ JL_DLLEXPORT int jl_cpu_cores(void)
372379
return info.dwNumberOfProcessors;
373380
}
374381
#else
382+
#warning "cpu core detection not defined for this platform"
375383
return 1;
376384
#endif
377385
}

0 commit comments

Comments
 (0)