/// <summary> /// [64bit Only] Use in environments with more than 64 logical processors /// </summary> public static unsafe void SetCurrentThreadAffinityW64(int __absolute__processors_index) { int g_cnt = __absolute__processors_index >> 6, i = 0; IntPtr handle = GetCurrentThread(); GROUP_AFFINITY ptr_temp; while (i < g_cnt) { ptr_temp = new GROUP_AFFINITY(UIntPtr.Zero, i++); SetThreadGroupAffinity(handle, &ptr_temp, null); } ptr_temp = new GROUP_AFFINITY( (UIntPtr)Mask(__absolute__processors_index & 0x3F), g_cnt); SetThreadGroupAffinity(handle, &ptr_temp, null); g_cnt = Environment.ProcessorCount >> 6; while (i < g_cnt) { ptr_temp = new GROUP_AFFINITY(UIntPtr.Zero, i++); SetThreadGroupAffinity(handle, &ptr_temp, null); } }
#pragma warning disable IDE1006 // 명명 스타일 private static unsafe void __SetGroupAffinity(int hc, int lc, uint hc_sel, uint lc_sel) { IntPtr handle = GetCurrentThread(); GROUP_AFFINITY ptr_temp; int ptr0_index = 0; // low position cores int g_idx = lc >> 6; while (--g_idx >= 0) { ptr_temp = new GROUP_AFFINITY((UIntPtr)(ulong.MaxValue * lc_sel), ptr0_index++); SetThreadGroupAffinity(handle, &ptr_temp, null); } // pc 중첩 요구 공간 vs ec 차지 후 잉여 공간 int _diff = CMath.Min(hc & 0x3F, 64 - (lc & 0x3F)); // combine ptr_temp = new GROUP_AFFINITY( (UIntPtr)((Mask(lc) * lc_sel) | ((Mask(_diff) * hc_sel) << lc)), ptr0_index++); SetThreadGroupAffinity(handle, &ptr_temp, null); // high position cores g_idx = hc >> 6; while (--g_idx >= 0) { ptr_temp = new GROUP_AFFINITY((UIntPtr)(ulong.MaxValue * hc_sel), ptr0_index++); SetThreadGroupAffinity(handle, &ptr_temp, null); } // 상위에 남은 공간이 존재 if ((hc & 0x3F) - _diff > 0) { ptr_temp = new GROUP_AFFINITY( (UIntPtr)(Mask(_diff) * hc_sel), ptr0_index); SetThreadGroupAffinity(handle, &ptr_temp, null); } // NOTE: a[i] = i; 연산에서 a[i]가 우선됨 // 'load ptr, load idx, load value, set value' 순서 }