From 81cff39d52bdda5ebd1aa12e88f305cfe2de49bd Mon Sep 17 00:00:00 2001 From: AlexGutenev Date: Sun, 8 Mar 2020 12:26:40 +0200 Subject: [PATCH 1/4] More precise std::hardware_concurrency --- stl/src/cthread.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/stl/src/cthread.cpp b/stl/src/cthread.cpp index 8f1c761cd5f..0f1b2d53db1 100644 --- a/stl/src/cthread.cpp +++ b/stl/src/cthread.cpp @@ -99,9 +99,16 @@ _Thrd_id_t _Thrd_id() { // return unique id for current thread } unsigned int _Thrd_hardware_concurrency() { // return number of processors - SYSTEM_INFO info; - GetNativeSystemInfo(&info); - return info.dwNumberOfProcessors; + DWORD_PTR process_affinity; + DWORD_PTR system_affinity; + if (GetProcessAffinityMask(GetCurrentProcess(), &process_affinity, &system_affinity)) +#ifdef _WIN64 + return __builtin_popcountll(process_affinity); +#else + return __builtin_popcount(process_affinity); +#endif // _WIN64 + else + return 0; } // TRANSITION, ABI: _Thrd_create() is preserved for binary compatibility From 9e3fa628035c4c1d99cb25588f4c9cc18ccca770 Mon Sep 17 00:00:00 2001 From: AlexGutenev Date: Mon, 9 Mar 2020 07:26:44 +0200 Subject: [PATCH 2/4] Code style: control flow braces, more specific varaible names, unneccessary comment removal --- stl/src/cthread.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/stl/src/cthread.cpp b/stl/src/cthread.cpp index 0f1b2d53db1..f5589db29f1 100644 --- a/stl/src/cthread.cpp +++ b/stl/src/cthread.cpp @@ -99,16 +99,17 @@ _Thrd_id_t _Thrd_id() { // return unique id for current thread } unsigned int _Thrd_hardware_concurrency() { // return number of processors - DWORD_PTR process_affinity; - DWORD_PTR system_affinity; - if (GetProcessAffinityMask(GetCurrentProcess(), &process_affinity, &system_affinity)) + DWORD_PTR process_affinity_mask; + DWORD_PTR system_affinity_mask; + if (GetProcessAffinityMask(GetCurrentProcess(), &process_affinity_mask, &system_affinity_mask)) { #ifdef _WIN64 - return __builtin_popcountll(process_affinity); + return __builtin_popcountll(process_affinity_mask); #else - return __builtin_popcount(process_affinity); -#endif // _WIN64 - else + return __builtin_popcount(process_affinity_mask); +#endif + } else { return 0; + } } // TRANSITION, ABI: _Thrd_create() is preserved for binary compatibility From 33f4e124ca3bb65b6404ab76079095a1def0408d Mon Sep 17 00:00:00 2001 From: AlexGutenev Date: Mon, 9 Mar 2020 12:52:14 +0200 Subject: [PATCH 3/4] let's go with --- stl/src/cthread.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/stl/src/cthread.cpp b/stl/src/cthread.cpp index f5589db29f1..65ade5575c6 100644 --- a/stl/src/cthread.cpp +++ b/stl/src/cthread.cpp @@ -4,6 +4,7 @@ // thread functions #include "awint.h" +#include "bitset" #include #include #include @@ -102,11 +103,9 @@ unsigned int _Thrd_hardware_concurrency() { // return number of processors DWORD_PTR process_affinity_mask; DWORD_PTR system_affinity_mask; if (GetProcessAffinityMask(GetCurrentProcess(), &process_affinity_mask, &system_affinity_mask)) { -#ifdef _WIN64 - return __builtin_popcountll(process_affinity_mask); -#else - return __builtin_popcount(process_affinity_mask); -#endif + std::bitset process_affinity_mask_bits( + static_cast(process_affinity_mask)); + return static_cast(process_affinity_mask_bits.count()); } else { return 0; } From 203026ea53ac87b683742f99ca769dd64d905bc9 Mon Sep 17 00:00:00 2001 From: Alex Guteniev Date: Wed, 11 Mar 2020 20:27:58 +0200 Subject: [PATCH 4/4] Good include quotes --- stl/src/cthread.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/src/cthread.cpp b/stl/src/cthread.cpp index 65ade5575c6..42a757f76f6 100644 --- a/stl/src/cthread.cpp +++ b/stl/src/cthread.cpp @@ -4,7 +4,7 @@ // thread functions #include "awint.h" -#include "bitset" +#include #include #include #include