Skip to content

Commit cf94e00

Browse files
authored
Added SetPriorityClass() and SetThreadPriority() to Kernel32 (#1544)
* Refactored error handling. * Added missing GetPriorityClass(), SetPriorityClass(), GetThreadPriority() and SetThreadPriority() methods to Kernel32 class. Added test cases for Kernel32.SetPriorityClass(), Kernel32.GetPriorityClass(), Kernel32.GetThreadPriority() and Kernel32.SetThreadPriority(). Also added some useful helper methods to Kernel32Util class, including tests. * Updated changelog.
1 parent 6c0fb98 commit cf94e00

File tree

5 files changed

+443
-47
lines changed

5 files changed

+443
-47
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Next Release (5.14.0)
88
Features
99
--------
1010
* [#1534](https://github.com/java-native-access/jna/pull/1534): Add `GetMethod`, `Put`, `SpawnInstance` to `c.s.j.p.win32.COM.WbemCli#IWbemClassObject` and `ExecMethod` to `c.s.j.p.win32.COM.WbemCli#IWbemServices` - [@faddom](https://github.com/faddom).
11+
* [#1544](https://github.com/java-native-access/jna/pull/1544): Add `GetPriorityClass`, `SetPriorityClass`, `GetThreadPriority`, `SetThreadPriority` and associated constants to `c.s.j.p.win32.Kernel32` - [@dEajL3kA](https://github.com/dEajL3kA).
1112

1213
Bug Fixes
1314
---------

contrib/platform/src/com/sun/jna/platform/win32/Kernel32.java

+77
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,44 @@ public interface Kernel32 extends StdCallLibrary, WinNT, Wincon {
6868
*/
6969
int LOAD_LIBRARY_AS_DATAFILE = 0x2;
7070

71+
/**
72+
* Process priority classes
73+
*/
74+
DWORD NORMAL_PRIORITY_CLASS = new DWORD(0x00000020L);
75+
DWORD IDLE_PRIORITY_CLASS = new DWORD(0x00000040L);
76+
DWORD HIGH_PRIORITY_CLASS = new DWORD(0x00000080L);
77+
DWORD REALTIME_PRIORITY_CLASS = new DWORD(0x00000100L);
78+
DWORD BELOW_NORMAL_PRIORITY_CLASS = new DWORD(0x00004000L);
79+
DWORD ABOVE_NORMAL_PRIORITY_CLASS = new DWORD(0x00008000L);
80+
81+
/**
82+
* Process mode flags
83+
*/
84+
DWORD PROCESS_MODE_BACKGROUND_BEGIN = new DWORD(0x00100000L);
85+
DWORD PROCESS_MODE_BACKGROUND_END = new DWORD(0x00200000L);
86+
87+
/**
88+
* Thread priorities
89+
*/
90+
int THREAD_PRIORITY_IDLE = -15;
91+
int THREAD_PRIORITY_LOWEST = -2;
92+
int THREAD_PRIORITY_BELOW_NORMAL = -1;
93+
int THREAD_PRIORITY_NORMAL = 0;
94+
int THREAD_PRIORITY_ABOVE_NORMAL = 1;
95+
int THREAD_PRIORITY_HIGHEST = 2;
96+
int THREAD_PRIORITY_TIME_CRITICAL = 15;
97+
98+
/**
99+
* Thread mode flags
100+
*/
101+
int THREAD_MODE_BACKGROUND_BEGIN = 0x10000;
102+
int THREAD_MODE_BACKGROUND_END = 0x20000;
103+
104+
/**
105+
* Thread priority error code
106+
*/
107+
int THREAD_PRIORITY_ERROR_RETURN = 0x7FFFFFFF;
108+
71109
/**
72110
* Reads data from the specified file or input/output (I/O) device. Reads
73111
* occur at the position specified by the file pointer if supported by the
@@ -4152,6 +4190,45 @@ Pointer VirtualAllocEx(HANDLE hProcess, Pointer lpAddress, SIZE_T dwSize,
41524190
*/
41534191
boolean GetExitCodeThread(HANDLE hThread, IntByReference exitCode);
41544192

4193+
/**
4194+
* Gets the priority class of the specified process.
4195+
*
4196+
* @param hProcess A handle to the process.
4197+
* @return If the function succeeds, the return value is the priority class of
4198+
* the specified process.
4199+
* <p>If the function fails, the return value is zero.</p>
4200+
*/
4201+
DWORD GetPriorityClass(HANDLE hProcess);
4202+
4203+
/**
4204+
* Sets the priority class for the specified process.
4205+
*
4206+
* @param hProcess A handle to the process.
4207+
* @param dwPriorityClass The priority class for the process.
4208+
* @return If the function succeeds, the return value is nonzero.
4209+
*/
4210+
boolean SetPriorityClass(HANDLE hProcess, DWORD dwPriorityClass);
4211+
4212+
/**
4213+
* Gets the priority value of the specified thread.
4214+
*
4215+
* @param hProcess A handle to the process.
4216+
* @return If the function succeeds, the return value is the priority class of
4217+
* the specified thread.
4218+
* <p>If the function fails, the return value is
4219+
* THREAD_PRIORITY_ERROR_RETURN.</p>
4220+
*/
4221+
int GetThreadPriority(HANDLE hProcess);
4222+
4223+
/**
4224+
* Sets the priority value for the specified thread.
4225+
*
4226+
* @param hThread A handle to the thread whose priority value is to be set.
4227+
* @param nPriority The priority value for the thread.
4228+
* @return If the function succeeds, the return value is nonzero.
4229+
*/
4230+
boolean SetThreadPriority(HANDLE hThread, int nPriority);
4231+
41554232
/**
41564233
* Releases, decommits, or releases and decommits a region of memory within
41574234
* the virtual address space of a specified process.

0 commit comments

Comments
 (0)