try 2 to use background priorities on windows, GitHub issue #126

dbus-notify
Zlatin Balevsky 2022-03-17 14:48:36 +00:00
parent 2737301252
commit 4fc6772dc3
No known key found for this signature in database
GPG Key ID: A72832072D525E41
2 changed files with 25 additions and 5 deletions

View File

@ -1,5 +1,7 @@
package com.muwire.gui.win
import com.sun.jna.platform.win32.BaseTSD
import com.sun.jna.platform.win32.WinDef
import com.sun.jna.platform.win32.WinNT.HANDLE
class PrioritySetter {
@ -9,10 +11,19 @@ class PrioritySetter {
}
static void enterBackgroundMode() {
MWKernel32.INSTANCE.SetPriorityClass(myProcess, 0x00100000)
// 1. set BELOW_NORMAL
MWKernel32.INSTANCE.SetPriorityClass(myProcess, new WinDef.DWORD(0x00004000L))
// 2. enter background mode
MWKernel32.INSTANCE.SetPriorityClass(myProcess, new WinDef.DWORD(0x00100000))
// 3. increase the process working set to something reasonable
def sizeT = new BaseTSD.SIZE_T(0x1L << 29) // 512 MB
MWKernel32.INSTANCE.SetProcessWorkingSetSizeEx(myProcess, sizeT, sizeT, new WinDef.DWORD(0x00000008L))
}
static void exitBackgroundMode() {
MWKernel32.INSTANCE.SetPriorityClass(myProcess, 0x00200000)
// 1. exit background mode
MWKernel32.INSTANCE.SetPriorityClass(myProcess, new WinDef.DWORD(0x00200000L))
// 2. set priority to normal
MWKernel32.INSTANCE.SetPriorityClass(myProcess, new WinDef.DWORD(0x00000020L))
}
}

View File

@ -1,12 +1,21 @@
package com.muwire.gui.win;
import com.sun.jna.Native;
import com.sun.jna.platform.win32.Kernel32;
import com.sun.jna.platform.win32.BaseTSD;
import com.sun.jna.platform.win32.WinDef;
import com.sun.jna.platform.win32.WinNT;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface MWKernel32 extends Kernel32 {
public interface MWKernel32 extends StdCallLibrary {
MWKernel32 INSTANCE = Native.load("kernel32", MWKernel32.class, W32APIOptions.DEFAULT_OPTIONS);
boolean SetPriorityClass(HANDLE hProcess, int mask);
WinDef.BOOL SetPriorityClass(WinNT.HANDLE hProcess, WinDef.DWORD mask);
WinNT.HANDLE GetCurrentProcess();
WinDef.BOOL SetProcessWorkingSetSizeEx(WinNT.HANDLE hProcess,
BaseTSD.SIZE_T minSize,
BaseTSD.SIZE_T maxSize,
WinDef.DWORD flags);
}