From eac38ffc4a42a52dae9403d9e5bc6f687f097681 Mon Sep 17 00:00:00 2001 From: Aoran Zeng Date: Tue, 3 Sep 2024 20:52:05 +0800 Subject: [PATCH] Get CPU cores --- include/chsrc.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/chsrc.h b/include/chsrc.h index 00274ce..bf09037 100644 --- a/include/chsrc.h +++ b/include/chsrc.h @@ -1117,3 +1117,21 @@ chsrc_get_cpuarch () } } + +static int +chsrc_get_cpucore () +{ + int cores = 2; + +#if XY_On_Windows + SYSTEM_INFO info; + GetSystemInfo (&info); + DWORD num = sysinfo.dwNumberOfProcessors + cores = (int)num; +#else + long num = sysconf(_SC_NPROCESSORS_ONLN); + cores = (int)num; +#endif + + return cores; +}