| 1 | /* $Id$ */
|
|---|
| 2 | /** @file
|
|---|
| 3 | * win_get_processor_group_active_mask - Helper.
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | /*
|
|---|
| 7 | * Copyright (c) 2020 knut st. osmundsen <bird-kBuild-spamxx@anduin.net>
|
|---|
| 8 | *
|
|---|
| 9 | * Permission is hereby granted, free of charge, to any person obtaining a
|
|---|
| 10 | * copy of this software and associated documentation files (the "Software"),
|
|---|
| 11 | * to deal in the Software without restriction, including without limitation
|
|---|
| 12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|---|
| 13 | * and/or sell copies of the Software, and to permit persons to whom the
|
|---|
| 14 | * Software is furnished to do so, subject to the following conditions:
|
|---|
| 15 | *
|
|---|
| 16 | * The above copyright notice and this permission notice shall be included
|
|---|
| 17 | * in all copies or substantial portions of the Software.
|
|---|
| 18 | *
|
|---|
| 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|---|
| 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|---|
| 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|---|
| 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|---|
| 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|---|
| 24 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|---|
| 25 | * IN THE SOFTWARE.
|
|---|
| 26 | *
|
|---|
| 27 | * Alternatively, the content of this file may be used under the terms of the
|
|---|
| 28 | * GPL version 2 or later, or LGPL version 2.1 or later.
|
|---|
| 29 | */
|
|---|
| 30 |
|
|---|
| 31 | /*********************************************************************************************************************************
|
|---|
| 32 | * Header Files *
|
|---|
| 33 | *********************************************************************************************************************************/
|
|---|
| 34 | #include <string.h>
|
|---|
| 35 | #include <Windows.h>
|
|---|
| 36 | #include "win_get_processor_group_active_mask.h"
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 | KAFFINITY win_get_processor_group_active_mask(unsigned iGroup)
|
|---|
| 40 | {
|
|---|
| 41 | union
|
|---|
| 42 | {
|
|---|
| 43 | SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX Info;
|
|---|
| 44 | SYSTEM_INFO SysInfo;
|
|---|
| 45 | char ab[8192];
|
|---|
| 46 | } uBuf;
|
|---|
| 47 | typedef BOOL (WINAPI *PFNGETLOGICALPROCESSORINFORMATIONEX)(LOGICAL_PROCESSOR_RELATIONSHIP,
|
|---|
| 48 | SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *, DWORD *);
|
|---|
| 49 | static PFNGETLOGICALPROCESSORINFORMATIONEX volatile s_pfnGetLogicalProcessorInformationEx = NULL;
|
|---|
| 50 | static HMODULE volatile s_hmodKernel32 = NULL;
|
|---|
| 51 | PFNGETLOGICALPROCESSORINFORMATIONEX pfnGetLogicalProcessorInformationEx = s_pfnGetLogicalProcessorInformationEx;
|
|---|
| 52 | if (!pfnGetLogicalProcessorInformationEx)
|
|---|
| 53 | {
|
|---|
| 54 | if (!s_hmodKernel32)
|
|---|
| 55 | {
|
|---|
| 56 | HMODULE hmodKernel32 = GetModuleHandleW(L"KERNEL32.DLL");
|
|---|
| 57 | s_hmodKernel32 = hmodKernel32;
|
|---|
| 58 | s_pfnGetLogicalProcessorInformationEx
|
|---|
| 59 | = pfnGetLogicalProcessorInformationEx
|
|---|
| 60 | = (PFNGETLOGICALPROCESSORINFORMATIONEX)GetProcAddress(hmodKernel32, "GetLogicalProcessorInformationEx");
|
|---|
| 61 | }
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | SetLastError(0);
|
|---|
| 65 | if (pfnGetLogicalProcessorInformationEx)
|
|---|
| 66 | {
|
|---|
| 67 | DWORD cbBuf;
|
|---|
| 68 | memset(&uBuf, 0, sizeof(uBuf));
|
|---|
| 69 | uBuf.Info.Size = cbBuf = sizeof(uBuf);
|
|---|
| 70 | if (pfnGetLogicalProcessorInformationEx(RelationGroup, &uBuf.Info, &cbBuf))
|
|---|
| 71 | {
|
|---|
| 72 | __debugbreak();
|
|---|
| 73 | SetLastError(0);
|
|---|
| 74 | if (iGroup < uBuf.Info.Group.MaximumGroupCount)
|
|---|
| 75 | return uBuf.Info.Group.GroupInfo[iGroup].ActiveProcessorMask;
|
|---|
| 76 | }
|
|---|
| 77 | }
|
|---|
| 78 | else if (iGroup == 0)
|
|---|
| 79 | {
|
|---|
| 80 | GetSystemInfo(&uBuf.SysInfo);
|
|---|
| 81 | return uBuf.SysInfo.dwActiveProcessorMask;
|
|---|
| 82 | }
|
|---|
| 83 | return 0;
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|