aboutsummaryrefslogtreecommitdiff
path: root/winsup/cygwin/miscfuncs.cc
diff options
context:
space:
mode:
authorMark Geisert <mark@maxrnd.com>2019-06-23 14:51:06 -0700
committerCorinna Vinschen <corinna@vinschen.de>2019-06-24 09:18:14 +0200
commit641ecb07533e85211b6abce334c85967f3f90209 (patch)
tree5f236ea53f41e33eb7a6ed631c5825c8414f8583 /winsup/cygwin/miscfuncs.cc
parentd54edfdf81b20832aff8627b31a579fb5ba0106e (diff)
downloadnewlib-641ecb07533e85211b6abce334c85967f3f90209.zip
newlib-641ecb07533e85211b6abce334c85967f3f90209.tar.gz
newlib-641ecb07533e85211b6abce334c85967f3f90209.tar.bz2
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.
Diffstat (limited to 'winsup/cygwin/miscfuncs.cc')
-rw-r--r--winsup/cygwin/miscfuncs.cc20
1 files changed, 16 insertions, 4 deletions
diff --git a/winsup/cygwin/miscfuncs.cc b/winsup/cygwin/miscfuncs.cc
index b5dfffc..e02bc9c 100644
--- a/winsup/cygwin/miscfuncs.cc
+++ b/winsup/cygwin/miscfuncs.cc
@@ -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;
+}