Skip to content

Commit

Permalink
Fea #62, 新增GetThreadGroupAffinity
Browse files Browse the repository at this point in the history
  • Loading branch information
sonyps5201314 authored and mingkuang-Chuyu committed Aug 10, 2023
1 parent 7d3b731 commit badef5c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions ThunksList.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
| *GetCurrentProcessorNumberEx | 不存在时,调用GetCurrentProcessorNumber。
| *GetNumaNodeProcessorMask | 不存在时,假定所有CPU都在当前Numa。
| *GetNumaNodeProcessorMaskEx | 不存在时,调用GetNumaNodeProcessorMask。
| *GetThreadGroupAffinity | 不存在时,调用NtQueryInformationThread。
| *SetThreadGroupAffinity | 不存在时,调用SetThreadAffinityMask。
| *CancelIoEx | 不存在时,调用CancelIo(会把此句柄的所有IO操作取消掉!)。
| *CancelSynchronousIo | 不存在时,仅返回失败。
Expand Down
51 changes: 51 additions & 0 deletions src/Thunks/api-ms-win-core-systemtopology.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,57 @@ namespace YY
}
#endif

#if (YY_Thunks_Support_Version < NTDDI_WIN7)

// Windows 7 [desktop apps only]
// Windows Server 2008 R2 [desktop apps only]
__DEFINE_THUNK(
kernel32,
8,
BOOL,
WINAPI,
GetThreadGroupAffinity,
_In_ HANDLE _hThread,
_Out_ PGROUP_AFFINITY _pAffinity
)
{
if (const auto _pfnGetThreadGroupAffinity = try_get_GetThreadGroupAffinity())
{
return _pfnGetThreadGroupAffinity(_hThread, _pAffinity);
}
else
{
if (!_pAffinity)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}

const auto _pfnNtQueryInformationThread = try_get_NtQueryInformationThread();
if (!_pfnNtQueryInformationThread)
{
SetLastError(ERROR_INVALID_FUNCTION);
return FALSE;
}

THREAD_BASIC_INFORMATION _ThreadBasicInfo;
long _Status = _pfnNtQueryInformationThread(_hThread, ThreadBasicInformation, &_ThreadBasicInfo, sizeof(_ThreadBasicInfo), nullptr);

if (_Status < 0)
{
internal::BaseSetLastNTError(_Status);
return FALSE;
}

_pAffinity->Group = 0;
_pAffinity->Mask = _ThreadBasicInfo.AffinityMask;
_pAffinity->Reserved[0] = 0;
_pAffinity->Reserved[1] = 0;
_pAffinity->Reserved[2] = 0;
return TRUE;
}
}
#endif

#if (YY_Thunks_Support_Version < NTDDI_WIN7)

Expand Down

0 comments on commit badef5c

Please sign in to comment.