public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-3383] libstdc++/thread: Implement `_GLIBCXX_NPROCS` for Windows
@ 2022-10-19 14:05 Jonathan Yong
  0 siblings, 0 replies; only message in thread
From: Jonathan Yong @ 2022-10-19 14:05 UTC (permalink / raw)
  To: gcc-cvs, libstdc++-cvs

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-10-19 14:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-19 14:05 [gcc r13-3383] libstdc++/thread: Implement `_GLIBCXX_NPROCS` for Windows Jonathan Yong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).