1
0
Fork 0
mirror of https://github.com/anrieff/libcpuid synced 2024-11-10 22:59:13 +00:00

Add support for get_total_cpus on *BSD and Solaris.

This commit is contained in:
Robert Kausch 2014-09-27 15:44:28 +02:00 committed by Veselin Georgiev
parent fa2083a992
commit 72d49bdd6f

View file

@ -113,7 +113,7 @@ static int get_total_cpus(void)
#define GET_TOTAL_CPUS_DEFINED #define GET_TOTAL_CPUS_DEFINED
#endif #endif
#if defined linux || defined __linux__ #if defined linux || defined __linux__ || defined __sun
#include <sys/sysinfo.h> #include <sys/sysinfo.h>
#include <unistd.h> #include <unistd.h>
@ -124,6 +124,20 @@ static int get_total_cpus(void)
#define GET_TOTAL_CPUS_DEFINED #define GET_TOTAL_CPUS_DEFINED
#endif #endif
#if defined __FreeBSD__ || defined __OpenBSD__ || defined __NetBSD__ || defined __bsdi__ || defined __QNX__
#include <sys/sysctl.h>
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 #ifndef GET_TOTAL_CPUS_DEFINED
static int get_total_cpus(void) static int get_total_cpus(void)
{ {