tuklib_cpucores.c | tuklib_cpucores.c | |||
---|---|---|---|---|
skipping to change at line 15 | skipping to change at line 15 | |||
// | // | |||
// Author: Lasse Collin | // Author: Lasse Collin | |||
// | // | |||
// This file has been put into the public domain. | // This file has been put into the public domain. | |||
// You can do whatever you want with this file. | // You can do whatever you want with this file. | |||
// | // | |||
/////////////////////////////////////////////////////////////////////////// //// | /////////////////////////////////////////////////////////////////////////// //// | |||
#include "tuklib_cpucores.h" | #include "tuklib_cpucores.h" | |||
#if defined(TUKLIB_CPUCORES_SYSCTL) | #if defined(_WIN32) || defined(__CYGWIN__) | |||
# ifndef _WIN32_WINNT | ||||
# define _WIN32_WINNT 0x0500 | ||||
# endif | ||||
# include <windows.h> | ||||
#elif defined(TUKLIB_CPUCORES_SYSCTL) | ||||
# ifdef HAVE_SYS_PARAM_H | # ifdef HAVE_SYS_PARAM_H | |||
# include <sys/param.h> | # include <sys/param.h> | |||
# endif | # endif | |||
# include <sys/sysctl.h> | # include <sys/sysctl.h> | |||
#elif defined(TUKLIB_CPUCORES_SYSCONF) | #elif defined(TUKLIB_CPUCORES_SYSCONF) | |||
# include <unistd.h> | # include <unistd.h> | |||
// HP-UX | // HP-UX | |||
#elif defined(TUKLIB_CPUCORES_PSTAT_GETDYNAMIC) | #elif defined(TUKLIB_CPUCORES_PSTAT_GETDYNAMIC) | |||
# include <sys/param.h> | # include <sys/param.h> | |||
# include <sys/pstat.h> | # include <sys/pstat.h> | |||
#endif | #endif | |||
extern uint32_t | extern uint32_t | |||
tuklib_cpucores(void) | tuklib_cpucores(void) | |||
{ | { | |||
uint32_t ret = 0; | uint32_t ret = 0; | |||
#if defined(TUKLIB_CPUCORES_SYSCTL) | #if defined(_WIN32) || defined(__CYGWIN__) | |||
SYSTEM_INFO sysinfo; | ||||
GetSystemInfo(&sysinfo); | ||||
ret = sysinfo.dwNumberOfProcessors; | ||||
#elif defined(TUKLIB_CPUCORES_SYSCTL) | ||||
int name[2] = { CTL_HW, HW_NCPU }; | int name[2] = { CTL_HW, HW_NCPU }; | |||
int cpus; | int cpus; | |||
size_t cpus_size = sizeof(cpus); | size_t cpus_size = sizeof(cpus); | |||
if (sysctl(name, 2, &cpus, &cpus_size, NULL, 0) != -1 | if (sysctl(name, 2, &cpus, &cpus_size, NULL, 0) != -1 | |||
&& cpus_size == sizeof(cpus) && cpus > 0) | && cpus_size == sizeof(cpus) && cpus > 0) | |||
ret = cpus; | ret = cpus; | |||
#elif defined(TUKLIB_CPUCORES_SYSCONF) | #elif defined(TUKLIB_CPUCORES_SYSCONF) | |||
# ifdef _SC_NPROCESSORS_ONLN | # ifdef _SC_NPROCESSORS_ONLN | |||
// Most systems | // Most systems | |||
End of changes. 2 change blocks. | ||||
2 lines changed or deleted | 13 lines changed or added | |||
This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/ |