From 72d49bdd6f4d3b03151c4f9632e201771fd04ae2 Mon Sep 17 00:00:00 2001 From: Robert Kausch Date: Sat, 27 Sep 2014 15:44:28 +0200 Subject: [PATCH] Add support for get_total_cpus on *BSD and Solaris. --- libcpuid/cpuid_main.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/libcpuid/cpuid_main.c b/libcpuid/cpuid_main.c index b13b30f..4a3293c 100644 --- a/libcpuid/cpuid_main.c +++ b/libcpuid/cpuid_main.c @@ -113,7 +113,7 @@ static int get_total_cpus(void) #define GET_TOTAL_CPUS_DEFINED #endif -#if defined linux || defined __linux__ +#if defined linux || defined __linux__ || defined __sun #include #include @@ -124,6 +124,20 @@ static int get_total_cpus(void) #define GET_TOTAL_CPUS_DEFINED #endif +#if defined __FreeBSD__ || defined __OpenBSD__ || defined __NetBSD__ || defined __bsdi__ || defined __QNX__ +#include + +static int get_total_cpus(void) +{ + int mib[2] = { CTL_HW, HW_NCPU }; + int ncpus; + size_t len = sizeof(ncpus); + if (sysctl(mib, 2, &ncpus, &len, (void *) 0, 0) != 0) return 1; + return ncpus; +} +#define GET_TOTAL_CPUS_DEFINED +#endif + #ifndef GET_TOTAL_CPUS_DEFINED static int get_total_cpus(void) {