mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-02-07 04:39:13 +01:00
DroidFish: Run the engine process with lower priority.
This commit is contained in:
parent
0d72a21f27
commit
a95dacafdf
|
@ -20,6 +20,8 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <sys/resource.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: org_petero_droidfish_engine_EngineUtil
|
* Class: org_petero_droidfish_engine_EngineUtil
|
||||||
|
@ -27,8 +29,7 @@
|
||||||
* Signature: (Ljava/lang/String;)Z
|
* Signature: (Ljava/lang/String;)Z
|
||||||
*/
|
*/
|
||||||
extern "C" JNIEXPORT jboolean JNICALL Java_org_petero_droidfish_engine_EngineUtil_chmod
|
extern "C" JNIEXPORT jboolean JNICALL Java_org_petero_droidfish_engine_EngineUtil_chmod
|
||||||
(JNIEnv *env, jclass, jstring jExePath)
|
(JNIEnv *env, jclass, jstring jExePath) {
|
||||||
{
|
|
||||||
const char* exePath = (*env).GetStringUTFChars(jExePath, NULL);
|
const char* exePath = (*env).GetStringUTFChars(jExePath, NULL);
|
||||||
if (!exePath)
|
if (!exePath)
|
||||||
return false;
|
return false;
|
||||||
|
@ -36,3 +37,14 @@ extern "C" JNIEXPORT jboolean JNICALL Java_org_petero_droidfish_engine_EngineUti
|
||||||
(*env).ReleaseStringUTFChars(jExePath, exePath);
|
(*env).ReleaseStringUTFChars(jExePath, exePath);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: org_petero_droidfish_engine_EngineUtil
|
||||||
|
* Method: reNice
|
||||||
|
* Signature: (II)V
|
||||||
|
*/
|
||||||
|
extern "C" JNIEXPORT void JNICALL Java_org_petero_droidfish_engine_EngineUtil_reNice
|
||||||
|
(JNIEnv *env, jclass, jint pid, jint prio) {
|
||||||
|
setpriority(PRIO_PROCESS, pid, prio);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -107,6 +107,9 @@ public class EngineUtil {
|
||||||
/** Executes chmod 744 exePath. */
|
/** Executes chmod 744 exePath. */
|
||||||
final static native boolean chmod(String 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. */
|
/** For synchronizing non thread safe native calls. */
|
||||||
public static Object nativeLock = new Object();
|
public static Object nativeLock = new Object();
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,6 +77,7 @@ public class ExternalEngine extends UCIEngineBase {
|
||||||
synchronized (EngineUtil.nativeLock) {
|
synchronized (EngineUtil.nativeLock) {
|
||||||
engineProc = pb.start();
|
engineProc = pb.start();
|
||||||
}
|
}
|
||||||
|
reNice(engineProc);
|
||||||
|
|
||||||
startupThread = new Thread(new Runnable() {
|
startupThread = new Thread(new Runnable() {
|
||||||
@Override
|
@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. */
|
/** Remove all files except exePath from exeDir. */
|
||||||
private void cleanUpExeDir(File exeDir, String exePath) {
|
private void cleanUpExeDir(File exeDir, String exePath) {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user