mirror of https://github.com/zlatinb/muwire
try 2 to use background priorities on windows, GitHub issue #126
parent
2737301252
commit
4fc6772dc3
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue