mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-12-12 17:12:40 +01:00
DroidFish: Do GTB initialization in a background thread.
This commit is contained in:
@@ -18,6 +18,8 @@
|
|||||||
|
|
||||||
package org.petero.droidfish.gtb;
|
package org.petero.droidfish.gtb;
|
||||||
|
|
||||||
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
|
|
||||||
/** Interface to native gtb probing code. */
|
/** Interface to native gtb probing code. */
|
||||||
class GtbProbe {
|
class GtbProbe {
|
||||||
static {
|
static {
|
||||||
@@ -25,14 +27,32 @@ class GtbProbe {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String currTbPath = "";
|
private String currTbPath = "";
|
||||||
|
private ConcurrentLinkedQueue<String> tbPathQueue = new ConcurrentLinkedQueue<String>();
|
||||||
|
|
||||||
GtbProbe() {
|
GtbProbe() {
|
||||||
}
|
}
|
||||||
|
|
||||||
final synchronized void setPath(String tbPath, boolean forceReload) {
|
public final void setPath(String tbPath, boolean forceReload) {
|
||||||
if (forceReload || !currTbPath.equals(tbPath)) {
|
if (forceReload || !tbPathQueue.isEmpty() || !currTbPath.equals(tbPath)) {
|
||||||
currTbPath = tbPath;
|
tbPathQueue.add(tbPath);
|
||||||
init(tbPath);
|
Thread t = new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
initIfNeeded();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
t.setPriority(Thread.MIN_PRIORITY);
|
||||||
|
t.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public final synchronized void initIfNeeded() {
|
||||||
|
String path = tbPathQueue.poll();
|
||||||
|
while (!tbPathQueue.isEmpty())
|
||||||
|
path = tbPathQueue.poll();
|
||||||
|
if (path != null) {
|
||||||
|
currTbPath = path;
|
||||||
|
init(currTbPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -143,9 +143,13 @@ public class Probe {
|
|||||||
epSquare = GtbProbe.NOSQUARE;
|
epSquare = GtbProbe.NOSQUARE;
|
||||||
|
|
||||||
int[] result = new int[2];
|
int[] result = new int[2];
|
||||||
boolean res = gtb.probeHard(pos.whiteMove, epSquare, castleMask,
|
boolean res = false;
|
||||||
whiteSquares, blackSquares, whitePieces, blackPieces,
|
if (nWhite + nBlack <= 5) {
|
||||||
result);
|
gtb.initIfNeeded();
|
||||||
|
res = gtb.probeHard(pos.whiteMove, epSquare, castleMask,
|
||||||
|
whiteSquares, blackSquares, whitePieces, blackPieces,
|
||||||
|
result);
|
||||||
|
}
|
||||||
ProbeResult ret = new ProbeResult();
|
ProbeResult ret = new ProbeResult();
|
||||||
if (res) {
|
if (res) {
|
||||||
switch (result[0]) {
|
switch (result[0]) {
|
||||||
|
|||||||
Reference in New Issue
Block a user