feat: added compilable cmake for core, added method to get physical core count.
This commit is contained in:
parent
1c6b515826
commit
734aee7d18
6 changed files with 113 additions and 0 deletions
26
core/src/thread_util.h
Normal file
26
core/src/thread_util.h
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#ifndef THREAD_UTIL_H
|
||||
#define THREAD_UTIL_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// Method return count of physical cores in system
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#include <windows.h>
|
||||
|
||||
size_t get_core_count(void) {
|
||||
SYSTEM_INFO sys_info;
|
||||
GetSystemInfo(&sys_info);
|
||||
|
||||
return (size_t)sys_info.dwNumberOfProcessors;
|
||||
}
|
||||
#elif defined(__unix__) || defined(__unix) || \
|
||||
(defined(__APPLE__) && defined(__MACH__))
|
||||
#include <unistd.h>
|
||||
|
||||
size_t get_core_count(void) { return (size_t)sysconf(_SC_NPROCESSORS_ONLN); }
|
||||
#else
|
||||
#error "Get core count feature not realised for current platform."
|
||||
#endif
|
||||
|
||||
#endif // !THREAD_UTIL_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue