mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-02-17 09:37:50 +01:00
DroidFish: Do GTB initialization in a background thread.
This commit is contained in:
parent
d442bb002e
commit
94f9994fe6
|
@ -18,6 +18,8 @@
|
|||
|
||||
package org.petero.droidfish.gtb;
|
||||
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
/** Interface to native gtb probing code. */
|
||||
class GtbProbe {
|
||||
static {
|
||||
|
@ -25,14 +27,32 @@ class GtbProbe {
|
|||
}
|
||||
|
||||
private String currTbPath = "";
|
||||
private ConcurrentLinkedQueue<String> tbPathQueue = new ConcurrentLinkedQueue<String>();
|
||||
|
||||
GtbProbe() {
|
||||
}
|
||||
|
||||
final synchronized void setPath(String tbPath, boolean forceReload) {
|
||||
if (forceReload || !currTbPath.equals(tbPath)) {
|
||||
currTbPath = tbPath;
|
||||
init(tbPath);
|
||||
public final void setPath(String tbPath, boolean forceReload) {
|
||||
if (forceReload || !tbPathQueue.isEmpty() || !currTbPath.equals(tbPath)) {
|
||||
tbPathQueue.add(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;
|
||||
|
||||
int[] result = new int[2];
|
||||
boolean res = gtb.probeHard(pos.whiteMove, epSquare, castleMask,
|
||||
whiteSquares, blackSquares, whitePieces, blackPieces,
|
||||
result);
|
||||
boolean res = false;
|
||||
if (nWhite + nBlack <= 5) {
|
||||
gtb.initIfNeeded();
|
||||
res = gtb.probeHard(pos.whiteMove, epSquare, castleMask,
|
||||
whiteSquares, blackSquares, whitePieces, blackPieces,
|
||||
result);
|
||||
}
|
||||
ProbeResult ret = new ProbeResult();
|
||||
if (res) {
|
||||
switch (result[0]) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user