rktio: get CPU count from the OS on FreeBSD and OpenBSD

This commit is contained in:
Bogdan Popa 2020-08-26 15:17:40 +03:00 committed by GitHub
parent a5ddbd3c9b
commit 1177112970
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,26 +1,18 @@
#include "rktio.h"
#include "rktio_private.h"
#if defined(__linux__) || defined(__QNX__)
#if defined(__linux__) || defined(__QNX__) || defined(OS_X) || defined(__FreeBSD__) || defined(__OpenBSD__)
# include <unistd.h>
#elif defined(OS_X)
# include <sys/param.h>
# include <sys/sysctl.h>
#elif defined(RKTIO_SYSTEM_WINDOWS)
# include <windows.h>
#endif
#endif
void rktio_init_cpu(rktio_t *rktio)
{
int processor_count;
#if defined(__linux__) || defined(__QNX__)
processor_count = sysconf(_SC_NPROCESSORS_ONLN);
#elif defined(OS_X)
size_t size = sizeof(processor_count);
if (sysctlbyname("hw.ncpu", &processor_count, &size, NULL, 0))
processor_count = 2;
#if defined(__linux__) || defined(__QNX__) || defined(OS_X) || defined(__FreeBSD__) || defined(__OpenBSD__)
processor_count = sysconf(_SC_NPROCESSORS_ONLN);
#elif defined(RKTIO_SYSTEM_WINDOWS)
SYSTEM_INFO sysinfo;
GetSystemInfo(&sysinfo);