From c9c4ca4f77ff3a52aac7eb476bda36f17d03b7f8 Mon Sep 17 00:00:00 2001 From: q66 Date: Fri, 25 Sep 2015 19:42:34 +0100 Subject: [PATCH] add ostd::cpu_count_get in platform.hh --- ostd/platform.hh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/ostd/platform.hh b/ostd/platform.hh index 9b2153a..5dde22b 100644 --- a/ostd/platform.hh +++ b/ostd/platform.hh @@ -71,6 +71,13 @@ # endif #endif +#ifndef OSTD_PLATFORM_WIN32 +#include +#else +#define WIN32_LEAN_AND_MEAN +#include +#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 \ No newline at end of file