Skip to content

Commit

Permalink
Added SetPriorityClass() and SetThreadPriority() to Kernel32 (#1544)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
danieltrick authored Aug 16, 2023
1 parent 6c0fb98 commit cf94e00
Show file tree
Hide file tree
Showing 5 changed files with 443 additions and 47 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Next Release (5.14.0)
Features
--------
* [#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).
* [#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).

Bug Fixes
---------
Expand Down
77 changes: 77 additions & 0 deletions contrib/platform/src/com/sun/jna/platform/win32/Kernel32.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,44 @@ public interface Kernel32 extends StdCallLibrary, WinNT, Wincon {
*/
int LOAD_LIBRARY_AS_DATAFILE = 0x2;

/**
* Process priority classes
*/
DWORD NORMAL_PRIORITY_CLASS = new DWORD(0x00000020L);
DWORD IDLE_PRIORITY_CLASS = new DWORD(0x00000040L);
DWORD HIGH_PRIORITY_CLASS = new DWORD(0x00000080L);
DWORD REALTIME_PRIORITY_CLASS = new DWORD(0x00000100L);
DWORD BELOW_NORMAL_PRIORITY_CLASS = new DWORD(0x00004000L);
DWORD ABOVE_NORMAL_PRIORITY_CLASS = new DWORD(0x00008000L);

/**
* Process mode flags
*/
DWORD PROCESS_MODE_BACKGROUND_BEGIN = new DWORD(0x00100000L);
DWORD PROCESS_MODE_BACKGROUND_END = new DWORD(0x00200000L);

/**
* Thread priorities
*/
int THREAD_PRIORITY_IDLE = -15;
int THREAD_PRIORITY_LOWEST = -2;
int THREAD_PRIORITY_BELOW_NORMAL = -1;
int THREAD_PRIORITY_NORMAL = 0;
int THREAD_PRIORITY_ABOVE_NORMAL = 1;
int THREAD_PRIORITY_HIGHEST = 2;
int THREAD_PRIORITY_TIME_CRITICAL = 15;

/**
* Thread mode flags
*/
int THREAD_MODE_BACKGROUND_BEGIN = 0x10000;
int THREAD_MODE_BACKGROUND_END = 0x20000;

/**
* Thread priority error code
*/
int THREAD_PRIORITY_ERROR_RETURN = 0x7FFFFFFF;

/**
* Reads data from the specified file or input/output (I/O) device. Reads
* occur at the position specified by the file pointer if supported by the
Expand Down Expand Up @@ -4152,6 +4190,45 @@ Pointer VirtualAllocEx(HANDLE hProcess, Pointer lpAddress, SIZE_T dwSize,
*/
boolean GetExitCodeThread(HANDLE hThread, IntByReference exitCode);

/**
* Gets the priority class of the specified process.
*
* @param hProcess A handle to the process.
* @return If the function succeeds, the return value is the priority class of
* the specified process.
* <p>If the function fails, the return value is zero.</p>
*/
DWORD GetPriorityClass(HANDLE hProcess);

/**
* Sets the priority class for the specified process.
*
* @param hProcess A handle to the process.
* @param dwPriorityClass The priority class for the process.
* @return If the function succeeds, the return value is nonzero.
*/
boolean SetPriorityClass(HANDLE hProcess, DWORD dwPriorityClass);

/**
* Gets the priority value of the specified thread.
*
* @param hProcess A handle to the process.
* @return If the function succeeds, the return value is the priority class of
* the specified thread.
* <p>If the function fails, the return value is
* THREAD_PRIORITY_ERROR_RETURN.</p>
*/
int GetThreadPriority(HANDLE hProcess);

/**
* Sets the priority value for the specified thread.
*
* @param hThread A handle to the thread whose priority value is to be set.
* @param nPriority The priority value for the thread.
* @return If the function succeeds, the return value is nonzero.
*/
boolean SetThreadPriority(HANDLE hThread, int nPriority);

/**
* Releases, decommits, or releases and decommits a region of memory within
* the virtual address space of a specified process.
Expand Down
Loading

0 comments on commit cf94e00

Please sign in to comment.