Detect right amount of cpu's available under osx. From Vaibhav Bhembre via github.

This commit is contained in:
Joris Vink 2013-07-28 19:21:49 +02:00
parent 659e19f92f
commit 3eb3665600
1 changed files with 19 additions and 0 deletions

View File

@ -17,6 +17,10 @@
#include <sys/param.h>
#include <sys/event.h>
#ifdef __MACH__
#include <sys/sysctl.h>
#endif
#include "kore.h"
static int kfd = -1;
@ -28,7 +32,22 @@ static u_int32_t event_count = 0;
void
kore_platform_init(void)
{
#ifndef __MACH__
cpu_count = 0;
#else
long n;
size_t len = sizeof(n);
int mib[] = { CTL_HW, HW_AVAILCPU };
sysctl(mib, 2, &n, &len, NULL, 0);
if (n < 1) {
mib[1] = HW_NCPU;
sysctl(mib, 2, &n, &len, NULL, 0);
}
if (n >= 1)
cpu_count = (u_int16_t)n;
#endif /* !__MACH__ */
}
void