mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-12-20 04:32:17 +01:00
DroidFish: Run the engine process with lower priority.
This commit is contained in:
@@ -107,6 +107,9 @@ public class EngineUtil {
|
||||
/** Executes chmod 744 exePath. */
|
||||
final static native boolean chmod(String exePath);
|
||||
|
||||
/** Change the priority of a process. */
|
||||
final static native void reNice(int pid, int prio);
|
||||
|
||||
/** For synchronizing non thread safe native calls. */
|
||||
public static Object nativeLock = new Object();
|
||||
}
|
||||
|
||||
@@ -77,6 +77,7 @@ public class ExternalEngine extends UCIEngineBase {
|
||||
synchronized (EngineUtil.nativeLock) {
|
||||
engineProc = pb.start();
|
||||
}
|
||||
reNice(engineProc);
|
||||
|
||||
startupThread = new Thread(new Runnable() {
|
||||
@Override
|
||||
@@ -168,6 +169,17 @@ public class ExternalEngine extends UCIEngineBase {
|
||||
}
|
||||
}
|
||||
|
||||
/** Try to change the engine process priority to 5. */
|
||||
private void reNice(Process proc) {
|
||||
try {
|
||||
java.lang.reflect.Field f = engineProc.getClass().getDeclaredField("pid");
|
||||
f.setAccessible(true);
|
||||
int pid = f.getInt(engineProc);
|
||||
EngineUtil.reNice(pid, 10);
|
||||
} catch (Throwable t) {
|
||||
}
|
||||
}
|
||||
|
||||
/** Remove all files except exePath from exeDir. */
|
||||
private void cleanUpExeDir(File exeDir, String exePath) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user