Cygwin: Implement sched_[gs]etaffinity()

This patch set implements the Linux syscalls sched_getaffinity,
sched_setaffinity, pthread_getaffinity_np, and pthread_setaffinity_np.
Linux has a straightforward view of the cpu sets used in affinity masks.
They are simply long (1024-bit) bit masks.  This code emulates that view
while internally dealing with Windows' distribution of available CPUs among
processor groups.
This commit is contained in:
Mark Geisert
2019-06-23 14:51:06 -07:00
committed by Corinna Vinschen
parent d54edfdf81
commit 641ecb0753
11 changed files with 389 additions and 5 deletions

View File

@ -963,17 +963,19 @@ SetThreadName(DWORD dwThreadID, const char* threadName)
#define add_size(p,s) ((p) = ((__typeof__(p))((PBYTE)(p)+(s))))
static WORD num_cpu_per_group = 0;
static WORD group_count = 0;
WORD
__get_cpus_per_group (void)
{
static WORD num_cpu_per_group = 0;
tmp_pathbuf tp;
if (num_cpu_per_group)
return num_cpu_per_group;
num_cpu_per_group = 64;
group_count = 1;
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX lpi =
(PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX) tp.c_get ();
@ -1005,10 +1007,20 @@ __get_cpus_per_group (void)
actually available CPUs. The ActiveProcessorCount is correct
though. So we just use ActiveProcessorCount for now, hoping for
the best. */
num_cpu_per_group
= plpi->Group.GroupInfo[0].ActiveProcessorCount;
num_cpu_per_group = plpi->Group.GroupInfo[0].ActiveProcessorCount;
/* Follow that lead to get the group count. */
group_count = plpi->Group.ActiveGroupCount;
break;
}
return num_cpu_per_group;
}
WORD
__get_group_count (void)
{
if (group_count == 0)
(void) __get_cpus_per_group (); // caller should have called this first
return group_count;
}