add ostd::cpu_count_get in platform.hh

master
Daniel Kolesa 2015-09-25 19:42:34 +01:00
parent 0c09c709b5
commit c9c4ca4f77
1 changed files with 23 additions and 0 deletions

View File

@ -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