diff options
author | Руслан Ижбулатов <lrn1986@gmail.com> | 2015-04-27 14:48:10 +0000 |
---|---|---|
committer | Руслан Ижбулатов <lrn1986@gmail.com> | 2016-04-26 13:52:45 +0000 |
commit | 999711abc82ea3a698d05977f9f91c0b73957f7f (patch) | |
tree | b8c6ae86aa7b2173f3ac0b18809c6f00b442f9e0 /glib/gthread.c | |
parent | 75589956a4ce3a78899ac9562dd43b431921108c (diff) | |
download | glib-999711abc82ea3a698d05977f9f91c0b73957f7f.tar.gz |
gthread: Better fallback for W32 g_get_num_processors()
https://bugzilla.gnome.org/show_bug.cgi?id=748530
Diffstat (limited to 'glib/gthread.c')
-rw-r--r-- | glib/gthread.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/glib/gthread.c b/glib/gthread.c index b9ae4dfa5..88554ebc5 100644 --- a/glib/gthread.c +++ b/glib/gthread.c @@ -1008,21 +1008,31 @@ guint g_get_num_processors (void) { #ifdef G_OS_WIN32 + unsigned int count; + SYSTEM_INFO sysinfo; DWORD_PTR process_cpus; DWORD_PTR system_cpus; + /* This *never* fails, use it as fallback */ + GetNativeSystemInfo (&sysinfo); + count = (int) sysinfo.dwNumberOfProcessors; + if (GetProcessAffinityMask (GetCurrentProcess (), &process_cpus, &system_cpus)) { - unsigned int count; + unsigned int af_count; - for (count = 0; process_cpus != 0; process_cpus >>= 1) + for (af_count = 0; process_cpus != 0; process_cpus >>= 1) if (process_cpus & 1) - count++; + af_count++; - if (count > 0) - return count; + /* Prefer affinity-based result, if available */ + if (af_count > 0) + count = af_count; } + + if (count > 0) + return count; #elif defined(_SC_NPROCESSORS_ONLN) { int count; |