mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 03:16:17 +01:00
gthread: Better fallback for W32 g_get_num_processors()
https://bugzilla.gnome.org/show_bug.cgi?id=748530
This commit is contained in:
parent
75589956a4
commit
999711abc8
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user