From b393d908a377ea456c32f27417169d5f4526695f Mon Sep 17 00:00:00 2001 From: David Hall Date: Thu, 17 Oct 2019 09:15:36 -0600 Subject: [PATCH] Added property to GROUP_AFFINITY to make it easier to get/set the list of affinitized processors. --- PInvoke/Kernel32/SystemTopologyApi.cs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/PInvoke/Kernel32/SystemTopologyApi.cs b/PInvoke/Kernel32/SystemTopologyApi.cs index f84b8d02..9dc76e48 100644 --- a/PInvoke/Kernel32/SystemTopologyApi.cs +++ b/PInvoke/Kernel32/SystemTopologyApi.cs @@ -1,5 +1,7 @@ using System; +using System.Collections.Generic; using System.Runtime.InteropServices; +using Vanara.Extensions; namespace Vanara.PInvoke { @@ -69,6 +71,29 @@ namespace Vanara.PInvoke /// This member is reserved. private ushort Reserved3; + + /// Gets or sets the affinitized processors in the field as their indexed values. + /// The affinitized processors. + public IEnumerable AffinitizedProcessors + { + get + { + var v = Mask.ToUInt64(); + for (uint i = 0; i < UIntPtr.Size * 8; i++) + { + if ((v & 0x1UL) == 1) + yield return i; + v = v >> 1; + } + } + set + { + var v = 0UL; + foreach (var i in value) + v |= 1UL << (int)i; + Mask = (UIntPtr)v; + } + } } } } \ No newline at end of file