winpthreads: affinity.c: port to modern Windows versions

Original implementation for `pthread_num_processors_np` and
`pthread_set_num_processors_np` functions was written before Windows added
support for more than 64 processors and introduced notion of processor groups.

Starting with Windows 7, 64-bit Windows supports more than 64 processors.

It introduced notion of processor groups; each processor is assigned to
processor group. On system with 64 or fewer processors, there is only one
processor group 0.

By default, all threads in a process are assigned to processor group 0.
Any thread can be assigned to any processor group at any point.

Starting with Windows 11, the default behavior was changed so that instead
of assigning all threads in a process to processor group 0, they can be
assigned to any processor group; that processor group is referred to as
the process' Primary Group.

By default, all threads in a process are assigned to that Primary Group.
The processor group a thread is assigned to is referred to as
the thread's Primary Group.

This change updates the implementation to make use of the following functions
introduced in Windows 7:

- `GetProcessGroupAffinity`
- `GetThreadGroupAffinity`

For pre-Windows 7 systems, these functions are emulated in a way that they
simply act as if there is only one processor group 0.

This change also makes use of `SetThreadAffinityMask`, which is available since
Windows NT 3.5 and on all Win9x systems. It is emulated for Windows NT 3.1.

Signed-off-by: Kirill Makurin <maiddaisuki@outlook.com>
Signed-off-by: LIU Hao <lh_mouse@126.com>
1 file changed