forked from OctaForge/libostd
add ostd::cpu_count_get in platform.hh
This commit is contained in:
parent
0c09c709b5
commit
c9c4ca4f77
|
@ -71,6 +71,13 @@
|
|||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef OSTD_PLATFORM_WIN32
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
namespace ostd {
|
||||
|
||||
#if defined(OSTD_TOOLCHAIN_GNU)
|
||||
|
@ -115,6 +122,22 @@ inline uint64_t endian_swap64(uint64_t x) {
|
|||
|
||||
#endif
|
||||
|
||||
inline int cpu_count_get() {
|
||||
static int count = 0;
|
||||
if (count <= 0) {
|
||||
#ifdef OSTD_PLATFORM_WIN32
|
||||
SYSTEM_INFO info;
|
||||
GetSystemInfo(&info);
|
||||
count = info.dwNumberOfProcessors;
|
||||
#elif defined(_SC_NPROCESSORS_ONLN)
|
||||
count = int(sysconf(_SC_NPROCESSORS_ONLN));
|
||||
#endif
|
||||
if (count <= 0)
|
||||
count = 1;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue