[gcc r13-3383] libstdc++/thread: Implement `_GLIBCXX_NPROCS` for Windows
Jonathan Yong
jyong@gcc.gnu.org
Wed Oct 19 14:05:43 GMT 2022
https://gcc.gnu.org/g:47684e58edc92ffdd4c636dbd34359b4c22e863a
commit r13-3383-g47684e58edc92ffdd4c636dbd34359b4c22e863a
Author: LIU Hao <lh_mouse@126.com>
Date: Sun Oct 2 00:57:08 2022 +0800
libstdc++/thread: Implement `_GLIBCXX_NPROCS` for Windows
This makes `std::thread::hardware_concurrency()` return the number of
logical processors, instead of zero.
libstdc++-v3/ChangeLog:
* src/c++11/thread.cc (get_nprocs): Add new implementation
for native Windows targets
Diff:
---
libstdc++-v3/src/c++11/thread.cc | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/libstdc++-v3/src/c++11/thread.cc b/libstdc++-v3/src/c++11/thread.cc
index 707a4ad415b..a54bc3e939a 100644
--- a/libstdc++-v3/src/c++11/thread.cc
+++ b/libstdc++-v3/src/c++11/thread.cc
@@ -68,6 +68,15 @@ static inline int get_nprocs()
#elif defined(_GLIBCXX_USE_SC_NPROC_ONLN)
# include <unistd.h>
# define _GLIBCXX_NPROCS sysconf(_SC_NPROC_ONLN)
+#elif defined(_WIN32)
+# include <windows.h>
+static inline int get_nprocs()
+{
+ SYSTEM_INFO sysinfo;
+ GetSystemInfo(&sysinfo);
+ return (int) sysinfo.dwNumberOfProcessors;
+}
+# define _GLIBCXX_NPROCS get_nprocs()
#else
# define _GLIBCXX_NPROCS 0
#endif
More information about the Libstdc++-cvs
mailing list