mirror of
https://github.com/upa/mscp.git
synced 2026-02-19 21:24:46 +08:00
initial commit
This commit is contained in:
27
src/platform.c
Normal file
27
src/platform.c
Normal file
@@ -0,0 +1,27 @@
|
||||
#include <util.h>
|
||||
#include <platform.h>
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
#elif linux
|
||||
#else
|
||||
#error unsupported platform
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __APPLE__
|
||||
int nr_cpus()
|
||||
{
|
||||
int n;
|
||||
size_t size = sizeof(n);
|
||||
|
||||
if (sysctlbyname("machdep.cpu.core_count", &n, &size, NULL, 0) != 0) {
|
||||
pr_err("failed to get number of cpu cores: %s\n", strerrno());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user