mirror of
https://github.com/upa/mscp.git
synced 2026-02-14 09:06:11 +08:00
compilable in linux
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
#include <util.h>
|
||||
#include <platform.h>
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
#elif linux
|
||||
#define _GNU_SOURCE
|
||||
#include <sched.h>
|
||||
#else
|
||||
#error unsupported platform
|
||||
#endif
|
||||
|
||||
#include <util.h>
|
||||
#include <platform.h>
|
||||
|
||||
#ifdef __APPLE__
|
||||
int nr_cpus()
|
||||
@@ -25,3 +26,13 @@ int nr_cpus()
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef linux
|
||||
int nr_cpus()
|
||||
{
|
||||
cpu_set_t cpu_set;
|
||||
if (sched_getaffinity(0, sizeof(cpu_set_t), &cpu_set) == 0)
|
||||
return CPU_COUNT(&cpu_set);
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user