Skip to content

Commit 75ff10e

Browse files
committed
Use _SC_NPROCESSORS_ONLN for CPU detection in BSDs.
Fixes #2328.
1 parent a1ad257 commit 75ff10e

File tree

1 file changed

+1
-22
lines changed

1 file changed

+1
-22
lines changed

src/host/os_getnumcpus.c

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -46,29 +46,8 @@ int do_getnumcpus()
4646
{
4747
return 0;
4848
}
49-
#elif PLATFORM_SOLARIS | PLATFORM_AIX | PLATFORM_MACOSX
49+
#elif PLATFORM_SOLARIS | PLATFORM_AIX | PLATFORM_MACOSX | PLATFORM_BSD
5050
return sysconf(_SC_NPROCESSORS_ONLN);
51-
#elif PLATFORM_BSD
52-
int mib[4];
53-
int numCPU;
54-
size_t len = sizeof(numCPU);
55-
56-
/* set the mib for hw.ncpu */
57-
mib[0] = CTL_HW;
58-
mib[1] = HW_AVAILCPU; // alternatively, try HW_NCPU;
59-
60-
/* get the number of CPUs from the system */
61-
sysctl(mib, 2, &numCPU, &len, NULL, 0);
62-
63-
if (numCPU < 1)
64-
{
65-
mib[1] = HW_NCPU;
66-
sysctl(mib, 2, &numCPU, &len, NULL, 0);
67-
if (numCPU < 1)
68-
return 0;
69-
}
70-
71-
return numCPU;
7251
#else
7352
#warning do_getnumcpus is not implemented for your platform yet
7453
return 0;

0 commit comments

Comments
 (0)