DroidFish: Run the engine process with lower priority.

This commit is contained in:
Peter Osterlund
2015-10-24 00:11:21 +02:00
parent 0d72a21f27
commit a95dacafdf
3 changed files with 29 additions and 2 deletions

View File

@@ -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();
}

View File

@@ -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 {