2004-01-10 02:14:13 +00:00
|
|
|
/*
|
2021-12-16 01:25:32 +00:00
|
|
|
* PROJECT: ReactOS Task Manager
|
2023-06-15 17:45:15 +00:00
|
|
|
* LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
|
2021-12-16 01:25:32 +00:00
|
|
|
* PURPOSE: Processor Affinity.
|
|
|
|
* COPYRIGHT: Copyright 1999-2001 Brian Palmer <brianp@reactos.org>
|
|
|
|
* Copyright 2005 Klemens Friedl <frik85@reactos.at>
|
2004-01-10 02:14:13 +00:00
|
|
|
*/
|
2005-05-08 04:07:56 +00:00
|
|
|
|
2013-01-24 23:00:42 +00:00
|
|
|
#include "precomp.h"
|
2004-01-10 02:14:13 +00:00
|
|
|
|
|
|
|
HANDLE hProcessAffinityHandle;
|
|
|
|
|
2007-07-26 14:48:47 +00:00
|
|
|
static const DWORD dwCpuTable[] = {
|
|
|
|
IDC_CPU0, IDC_CPU1, IDC_CPU2, IDC_CPU3,
|
|
|
|
IDC_CPU4, IDC_CPU5, IDC_CPU6, IDC_CPU7,
|
|
|
|
IDC_CPU8, IDC_CPU9, IDC_CPU10, IDC_CPU11,
|
|
|
|
IDC_CPU12, IDC_CPU13, IDC_CPU14, IDC_CPU15,
|
|
|
|
IDC_CPU16, IDC_CPU17, IDC_CPU18, IDC_CPU19,
|
|
|
|
IDC_CPU20, IDC_CPU21, IDC_CPU22, IDC_CPU23,
|
|
|
|
IDC_CPU24, IDC_CPU25, IDC_CPU26, IDC_CPU27,
|
|
|
|
IDC_CPU28, IDC_CPU29, IDC_CPU30, IDC_CPU31,
|
|
|
|
};
|
|
|
|
|
|
|
|
static INT_PTR CALLBACK AffinityDialogWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
|
2004-01-10 02:14:13 +00:00
|
|
|
|
|
|
|
void ProcessPage_OnSetAffinity(void)
|
|
|
|
{
|
2007-10-31 23:26:27 +00:00
|
|
|
DWORD dwProcessId;
|
|
|
|
WCHAR strErrorText[260];
|
2008-02-15 19:22:55 +00:00
|
|
|
WCHAR szTitle[256];
|
2004-01-10 02:14:13 +00:00
|
|
|
|
2009-06-28 14:22:09 +00:00
|
|
|
dwProcessId = GetSelectedProcessId();
|
|
|
|
|
|
|
|
if (dwProcessId == 0)
|
2004-01-10 02:14:13 +00:00
|
|
|
return;
|
2009-06-28 14:22:09 +00:00
|
|
|
|
2004-01-10 02:14:13 +00:00
|
|
|
hProcessAffinityHandle = OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_SET_INFORMATION, FALSE, dwProcessId);
|
|
|
|
if (!hProcessAffinityHandle) {
|
2023-06-15 07:22:43 +00:00
|
|
|
GetLastErrorText(strErrorText, _countof(strErrorText));
|
|
|
|
LoadStringW(hInst, IDS_MSG_ACCESSPROCESSAFF, szTitle, _countof(szTitle));
|
2008-02-15 19:22:55 +00:00
|
|
|
MessageBoxW(hMainWnd, strErrorText, szTitle, MB_OK|MB_ICONSTOP);
|
2004-01-10 02:14:13 +00:00
|
|
|
return;
|
|
|
|
}
|
2007-11-09 15:26:02 +00:00
|
|
|
DialogBoxW(hInst, MAKEINTRESOURCEW(IDD_AFFINITY_DIALOG), hMainWnd, AffinityDialogWndProc);
|
2004-01-10 02:14:13 +00:00
|
|
|
if (hProcessAffinityHandle) {
|
|
|
|
CloseHandle(hProcessAffinityHandle);
|
|
|
|
hProcessAffinityHandle = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-10-11 21:08:06 +00:00
|
|
|
INT_PTR CALLBACK
|
|
|
|
AffinityDialogWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
2004-01-10 02:14:13 +00:00
|
|
|
{
|
2009-02-03 23:03:35 +00:00
|
|
|
DWORD_PTR dwProcessAffinityMask = 0;
|
|
|
|
DWORD_PTR dwSystemAffinityMask = 0;
|
2007-10-31 23:26:27 +00:00
|
|
|
WCHAR strErrorText[260];
|
2008-02-15 19:22:55 +00:00
|
|
|
WCHAR szTitle[256];
|
2007-10-31 23:26:27 +00:00
|
|
|
BYTE nCpu;
|
2004-01-10 02:14:13 +00:00
|
|
|
|
|
|
|
switch (message) {
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the current affinity mask for the process and
|
|
|
|
* the number of CPUs present in the system
|
|
|
|
*/
|
|
|
|
if (!GetProcessAffinityMask(hProcessAffinityHandle, &dwProcessAffinityMask, &dwSystemAffinityMask)) {
|
2023-06-15 07:22:43 +00:00
|
|
|
GetLastErrorText(strErrorText, _countof(strErrorText));
|
2004-01-10 02:14:13 +00:00
|
|
|
EndDialog(hDlg, 0);
|
2023-06-15 07:22:43 +00:00
|
|
|
LoadStringW(hInst, IDS_MSG_ACCESSPROCESSAFF, szTitle, _countof(szTitle));
|
2008-02-15 19:22:55 +00:00
|
|
|
MessageBoxW(hMainWnd, strErrorText, szTitle, MB_OK|MB_ICONSTOP);
|
2004-01-10 02:14:13 +00:00
|
|
|
}
|
|
|
|
|
2023-06-15 07:22:43 +00:00
|
|
|
for (nCpu = 0; nCpu < _countof(dwCpuTable); nCpu++) {
|
2007-07-26 14:48:47 +00:00
|
|
|
/*
|
|
|
|
* Enable a checkbox for each processor present in the system
|
|
|
|
*/
|
|
|
|
if (dwSystemAffinityMask & (1 << nCpu))
|
|
|
|
EnableWindow(GetDlgItem(hDlg, dwCpuTable[nCpu]), TRUE);
|
|
|
|
/*
|
|
|
|
* Check each checkbox that the current process
|
|
|
|
* has affinity with
|
|
|
|
*/
|
|
|
|
if (dwProcessAffinityMask & (1 << nCpu))
|
2012-12-24 10:51:02 +00:00
|
|
|
CheckDlgButton(hDlg, dwCpuTable[nCpu], BST_CHECKED);
|
2007-07-26 14:48:47 +00:00
|
|
|
}
|
2004-01-10 02:14:13 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case WM_COMMAND:
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the user has cancelled the dialog box
|
|
|
|
* then just close it
|
|
|
|
*/
|
|
|
|
if (LOWORD(wParam) == IDCANCEL) {
|
|
|
|
EndDialog(hDlg, LOWORD(wParam));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The user has clicked OK -- so now we have
|
|
|
|
* to adjust the process affinity mask
|
|
|
|
*/
|
|
|
|
if (LOWORD(wParam) == IDOK) {
|
2023-06-15 07:22:43 +00:00
|
|
|
for (nCpu = 0; nCpu < _countof(dwCpuTable); nCpu++) {
|
2007-07-26 14:48:47 +00:00
|
|
|
/*
|
|
|
|
* First we have to create a mask out of each
|
|
|
|
* checkbox that the user checked.
|
|
|
|
*/
|
2012-12-24 10:51:02 +00:00
|
|
|
if (IsDlgButtonChecked(hDlg, dwCpuTable[nCpu]))
|
2007-07-26 14:48:47 +00:00
|
|
|
dwProcessAffinityMask |= (1 << nCpu);
|
|
|
|
}
|
2004-01-10 02:14:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure they are giving the process affinity
|
|
|
|
* with at least one processor. I'd hate to see a
|
|
|
|
* process that is not in a wait state get deprived
|
|
|
|
* of it's cpu time.
|
|
|
|
*/
|
|
|
|
if (!dwProcessAffinityMask) {
|
2023-06-15 07:22:43 +00:00
|
|
|
LoadStringW(hInst, IDS_MSG_PROCESSONEPRO, strErrorText, _countof(strErrorText));
|
|
|
|
LoadStringW(hInst, IDS_MSG_INVALIDOPTION, szTitle, _countof(szTitle));
|
2008-02-15 19:22:55 +00:00
|
|
|
MessageBoxW(hDlg, strErrorText, szTitle, MB_OK|MB_ICONSTOP);
|
2004-01-10 02:14:13 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to set the process affinity
|
|
|
|
*/
|
|
|
|
if (!SetProcessAffinityMask(hProcessAffinityHandle, dwProcessAffinityMask)) {
|
2023-06-15 07:22:43 +00:00
|
|
|
GetLastErrorText(strErrorText, _countof(strErrorText));
|
2004-01-10 02:14:13 +00:00
|
|
|
EndDialog(hDlg, LOWORD(wParam));
|
2023-06-15 07:22:43 +00:00
|
|
|
LoadStringW(hInst, IDS_MSG_ACCESSPROCESSAFF, szTitle, _countof(szTitle));
|
2008-02-15 19:22:55 +00:00
|
|
|
MessageBoxW(hMainWnd, strErrorText, szTitle, MB_OK|MB_ICONSTOP);
|
2004-01-10 02:14:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EndDialog(hDlg, LOWORD(wParam));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|