mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-26 15:36:14 +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)
|
g_get_num_processors (void)
|
||||||
{
|
{
|
||||||
#ifdef G_OS_WIN32
|
#ifdef G_OS_WIN32
|
||||||
|
unsigned int count;
|
||||||
|
SYSTEM_INFO sysinfo;
|
||||||
DWORD_PTR process_cpus;
|
DWORD_PTR process_cpus;
|
||||||
DWORD_PTR system_cpus;
|
DWORD_PTR system_cpus;
|
||||||
|
|
||||||
|
/* This *never* fails, use it as fallback */
|
||||||
|
GetNativeSystemInfo (&sysinfo);
|
||||||
|
count = (int) sysinfo.dwNumberOfProcessors;
|
||||||
|
|
||||||
if (GetProcessAffinityMask (GetCurrentProcess (),
|
if (GetProcessAffinityMask (GetCurrentProcess (),
|
||||||
&process_cpus, &system_cpus))
|
&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)
|
if (process_cpus & 1)
|
||||||
count++;
|
af_count++;
|
||||||
|
|
||||||
if (count > 0)
|
/* Prefer affinity-based result, if available */
|
||||||
return count;
|
if (af_count > 0)
|
||||||
|
count = af_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (count > 0)
|
||||||
|
return count;
|
||||||
#elif defined(_SC_NPROCESSORS_ONLN)
|
#elif defined(_SC_NPROCESSORS_ONLN)
|
||||||
{
|
{
|
||||||
int count;
|
int count;
|
||||||
|
Loading…
Reference in New Issue
Block a user