]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++/thread: Implement `_GLIBCXX_NPROCS` for Windows
authorLIU Hao <lh_mouse@126.com>
Sat, 1 Oct 2022 16:57:08 +0000 (00:57 +0800)
committerJonathan Yong <10walls@gmail.com>
Wed, 19 Oct 2022 14:05:33 +0000 (14:05 +0000)
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

libstdc++-v3/src/c++11/thread.cc

index 707a4ad415b935d27aac5b5dcbe10622d7e85932..a54bc3e939a01f0754c2431599041a6a30b507cb 100644 (file)
@@ -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