ReactOS 0.4.15-dev-8102-g108db8f
affinity.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Task Manager
3 * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4 * PURPOSE: Processor Affinity.
5 * COPYRIGHT: Copyright 1999-2001 Brian Palmer <brianp@reactos.org>
6 * Copyright 2005 Klemens Friedl <frik85@reactos.at>
7 */
8
9#include "precomp.h"
10
12
13static const DWORD dwCpuTable[] = {
22};
23
25
27{
28 DWORD dwProcessId;
29 WCHAR strErrorText[260];
30 WCHAR szTitle[256];
31
32 dwProcessId = GetSelectedProcessId();
33
34 if (dwProcessId == 0)
35 return;
36
39 GetLastErrorText(strErrorText, _countof(strErrorText));
42 return;
43 }
48 }
49}
50
53{
54 DWORD_PTR dwProcessAffinityMask = 0;
55 DWORD_PTR dwSystemAffinityMask = 0;
56 WCHAR strErrorText[260];
57 WCHAR szTitle[256];
58 BYTE nCpu;
59
60 switch (message) {
61 case WM_INITDIALOG:
62
63 /*
64 * Get the current affinity mask for the process and
65 * the number of CPUs present in the system
66 */
67 if (!GetProcessAffinityMask(hProcessAffinityHandle, &dwProcessAffinityMask, &dwSystemAffinityMask)) {
68 GetLastErrorText(strErrorText, _countof(strErrorText));
69 EndDialog(hDlg, 0);
72 }
73
74 for (nCpu = 0; nCpu < _countof(dwCpuTable); nCpu++) {
75 /*
76 * Enable a checkbox for each processor present in the system
77 */
78 if (dwSystemAffinityMask & ((ULONG_PTR)1 << nCpu))
80 /*
81 * Check each checkbox that the current process
82 * has affinity with
83 */
84 if (dwProcessAffinityMask & ((ULONG_PTR)1 << nCpu))
86 }
87
88 return TRUE;
89
90 case WM_COMMAND:
91
92 /*
93 * If the user has cancelled the dialog box
94 * then just close it
95 */
96 if (LOWORD(wParam) == IDCANCEL) {
97 EndDialog(hDlg, LOWORD(wParam));
98 return TRUE;
99 }
100
101 /*
102 * The user has clicked OK -- so now we have
103 * to adjust the process affinity mask
104 */
105 if (LOWORD(wParam) == IDOK) {
106 for (nCpu = 0; nCpu < _countof(dwCpuTable); nCpu++) {
107 /*
108 * First we have to create a mask out of each
109 * checkbox that the user checked.
110 */
111 if (IsDlgButtonChecked(hDlg, dwCpuTable[nCpu]))
112 dwProcessAffinityMask |= ((ULONG_PTR)1 << nCpu);
113 }
114
115 /*
116 * Make sure they are giving the process affinity
117 * with at least one processor. I'd hate to see a
118 * process that is not in a wait state get deprived
119 * of it's cpu time.
120 */
121 if (!dwProcessAffinityMask) {
122 LoadStringW(hInst, IDS_MSG_PROCESSONEPRO, strErrorText, _countof(strErrorText));
124 MessageBoxW(hDlg, strErrorText, szTitle, MB_OK|MB_ICONSTOP);
125 return TRUE;
126 }
127
128 /*
129 * Try to set the process affinity
130 */
131 if (!SetProcessAffinityMask(hProcessAffinityHandle, dwProcessAffinityMask)) {
132 GetLastErrorText(strErrorText, _countof(strErrorText));
133 EndDialog(hDlg, LOWORD(wParam));
136 }
137
138 EndDialog(hDlg, LOWORD(wParam));
139 return TRUE;
140 }
141
142 break;
143 }
144
145 return 0;
146}
static const DWORD dwCpuTable[]
Definition: affinity.c:13
static INT_PTR CALLBACK AffinityDialogWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
Definition: affinity.c:52
void ProcessPage_OnSetAffinity(void)
Definition: affinity.c:26
HANDLE hProcessAffinityHandle
Definition: affinity.c:11
#define IDC_CPU4
Definition: resource.h:49
#define IDC_CPU26
Definition: resource.h:111
#define IDC_CPU16
Definition: resource.h:84
#define IDC_CPU22
Definition: resource.h:102
#define IDC_CPU2
Definition: resource.h:45
#define IDC_CPU28
Definition: resource.h:117
#define IDC_CPU25
Definition: resource.h:108
#define IDC_CPU12
Definition: resource.h:72
#define IDC_CPU19
Definition: resource.h:93
#define IDC_CPU3
Definition: resource.h:47
#define IDC_CPU9
Definition: resource.h:62
#define IDC_CPU23
Definition: resource.h:104
#define IDC_CPU21
Definition: resource.h:99
#define IDC_CPU10
Definition: resource.h:65
#define IDS_MSG_PROCESSONEPRO
Definition: resource.h:248
#define IDC_CPU29
Definition: resource.h:120
#define IDC_CPU20
Definition: resource.h:96
#define IDC_CPU6
Definition: resource.h:54
#define IDC_CPU18
Definition: resource.h:90
#define IDC_CPU14
Definition: resource.h:78
#define IDC_CPU5
Definition: resource.h:51
#define IDS_MSG_INVALIDOPTION
Definition: resource.h:249
#define IDC_CPU0
Definition: resource.h:43
#define IDD_AFFINITY_DIALOG
Definition: resource.h:30
#define IDC_CPU8
Definition: resource.h:59
#define IDC_CPU11
Definition: resource.h:69
#define IDC_CPU1
Definition: resource.h:44
#define IDS_MSG_ACCESSPROCESSAFF
Definition: resource.h:247
#define IDC_CPU31
Definition: resource.h:127
#define IDC_CPU30
Definition: resource.h:124
#define IDC_CPU24
Definition: resource.h:105
#define IDC_CPU15
Definition: resource.h:81
#define IDC_CPU7
Definition: resource.h:56
#define IDC_CPU13
Definition: resource.h:75
#define IDC_CPU17
Definition: resource.h:87
#define IDC_CPU27
Definition: resource.h:114
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define CALLBACK
Definition: compat.h:35
HANDLE WINAPI OpenProcess(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwProcessId)
Definition: proc.c:1227
BOOL WINAPI SetProcessAffinityMask(IN HANDLE hProcess, IN DWORD_PTR dwProcessAffinityMask)
Definition: proc.c:894
BOOL WINAPI GetProcessAffinityMask(IN HANDLE hProcess, OUT PDWORD_PTR lpProcessAffinityMask, OUT PDWORD_PTR lpSystemAffinityMask)
Definition: proc.c:863
HINSTANCE hInst
Definition: dxdiag.c:13
unsigned long DWORD
Definition: ntddk_ex.h:95
#define PROCESS_QUERY_INFORMATION
Definition: pstypes.h:166
#define PROCESS_SET_INFORMATION
Definition: pstypes.h:165
TCHAR szTitle[MAX_LOADSTRING]
Definition: magnifier.c:35
HWND hMainWnd
Definition: magnifier.c:32
unsigned int UINT
Definition: ndis.h:50
#define LOWORD(l)
Definition: pedump.c:82
DWORD GetSelectedProcessId(void)
Definition: procpage.c:88
#define _countof(array)
Definition: sndvol32.h:70
Definition: tftpd.h:60
LPWSTR GetLastErrorText(LPWSTR lpszBuf, DWORD dwSize)
Definition: taskmgr.c:1083
int32_t INT_PTR
Definition: typedefs.h:64
uint32_t DWORD_PTR
Definition: typedefs.h:65
uint32_t ULONG_PTR
Definition: typedefs.h:65
LONG_PTR LPARAM
Definition: windef.h:208
UINT_PTR WPARAM
Definition: windef.h:207
BOOL WINAPI CheckDlgButton(_In_ HWND, _In_ int, _In_ UINT)
#define IDCANCEL
Definition: winuser.h:831
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define DialogBoxW(i, t, p, f)
Definition: winuser.h:4399
#define WM_COMMAND
Definition: winuser.h:1740
#define WM_INITDIALOG
Definition: winuser.h:1739
int WINAPI MessageBoxW(_In_opt_ HWND hWnd, _In_opt_ LPCWSTR lpText, _In_opt_ LPCWSTR lpCaption, _In_ UINT uType)
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define IDOK
Definition: winuser.h:830
UINT WINAPI IsDlgButtonChecked(_In_ HWND, _In_ int)
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
#define MB_OK
Definition: winuser.h:790
#define MB_ICONSTOP
Definition: winuser.h:803
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define BST_CHECKED
Definition: winuser.h:197
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned char BYTE
Definition: xxhash.c:193