aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLIU Hao <lh_mouse@126.com>2022-10-02 00:57:08 +0800
committerJonathan Yong <10walls@gmail.com>2022-10-19 14:05:33 +0000
commit47684e58edc92ffdd4c636dbd34359b4c22e863a (patch)
tree6c5ecfca0ce9ec2f555061f82a6b7dd59b5e0058
parentd32969898e113e86e1c42b0c6f096f8228cbf1ff (diff)
downloadgcc-47684e58edc92ffdd4c636dbd34359b4c22e863a.zip
gcc-47684e58edc92ffdd4c636dbd34359b4c22e863a.tar.gz
gcc-47684e58edc92ffdd4c636dbd34359b4c22e863a.tar.bz2
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
-rw-r--r--libstdc++-v3/src/c++11/thread.cc9
1 files changed, 9 insertions, 0 deletions
diff --git a/libstdc++-v3/src/c++11/thread.cc b/libstdc++-v3/src/c++11/thread.cc
index 707a4ad..a54bc3e 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