[glib] gthread: Better fallback for W32 g_get_num_processors()
- From: Руслан Ижбулатов <ruslanizhb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] gthread: Better fallback for W32 g_get_num_processors()
- Date: Tue, 26 Apr 2016 13:54:17 +0000 (UTC)
commit 999711abc82ea3a698d05977f9f91c0b73957f7f
Author: Руслан Ижбулатов <lrn1986 gmail com>
Date: Mon Apr 27 14:48:10 2015 +0000
gthread: Better fallback for W32 g_get_num_processors()
https://bugzilla.gnome.org/show_bug.cgi?id=748530
glib/gthread.c | 20 +++++++++++++++-----
1 files changed, 15 insertions(+), 5 deletions(-)
---
diff --git a/glib/gthread.c b/glib/gthread.c
index b9ae4df..88554eb 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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]