mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-18 22:26:30 +01:00
add ability to tag events as UI or not. CMD_DO is not. Only UI
events in queue prevent engine from continuing. This fixes bug where server running engine on behalf of robot would starve the UI thread by looping forever seeing the engine bail because a CMD_DO was in the queue and then adding a CMD_DO to try running the engine yet again.
This commit is contained in:
parent
3b7abc2a31
commit
f9afcc0e6f
2 changed files with 21 additions and 7 deletions
|
@ -592,7 +592,7 @@ public class BoardActivity extends Activity implements UtilCtxt {
|
|||
m_handler.post( new Runnable() {
|
||||
public void run() {
|
||||
if ( null != m_jniThread ) {
|
||||
m_jniThread.handle( JNIThread.JNICmd.CMD_DO );
|
||||
m_jniThread.handle( JNIThread.JNICmd.CMD_DO, false );
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.eehouse.android.xw4.Utils;
|
|||
import android.content.Context;
|
||||
import java.lang.InterruptedException;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.Iterator;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.graphics.Paint;
|
||||
|
@ -99,10 +100,11 @@ public class JNIThread extends Thread {
|
|||
LinkedBlockingQueue<QueueElem> m_queue;
|
||||
|
||||
private class QueueElem {
|
||||
protected QueueElem( JNICmd cmd, Object[] args )
|
||||
protected QueueElem( JNICmd cmd, boolean isUI, Object[] args )
|
||||
{
|
||||
m_cmd = cmd; m_args = args;
|
||||
m_cmd = cmd; m_isUIEvent = isUI; m_args = args;
|
||||
}
|
||||
boolean m_isUIEvent;
|
||||
JNICmd m_cmd;
|
||||
Object[] m_args;
|
||||
}
|
||||
|
@ -132,8 +134,15 @@ public class JNIThread extends Thread {
|
|||
|
||||
public boolean busy()
|
||||
{ // synchronize this!!!
|
||||
int siz = m_queue.size();
|
||||
return siz > 0;
|
||||
boolean result = false;
|
||||
Iterator<QueueElem> iter = m_queue.iterator();
|
||||
while ( iter.hasNext() ) {
|
||||
if ( iter.next().m_isUIEvent ) {
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setInBackground( boolean inBack )
|
||||
|
@ -488,11 +497,16 @@ public class JNIThread extends Thread {
|
|||
Utils.logf( "run exiting" );
|
||||
} // run
|
||||
|
||||
public void handle( JNICmd cmd, Object... args )
|
||||
public void handle( JNICmd cmd, boolean isUI, Object... args )
|
||||
{
|
||||
QueueElem elem = new QueueElem( cmd, args );
|
||||
QueueElem elem = new QueueElem( cmd, isUI, args );
|
||||
// Utils.logf( "adding: " + cmd.toString() );
|
||||
m_queue.add( elem );
|
||||
}
|
||||
|
||||
public void handle( JNICmd cmd, Object... args )
|
||||
{
|
||||
handle( cmd, true, args );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue