File tree Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change 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}
You can’t perform that action at this time.
0 commit comments