check for existing JNIThread first

When loading gamelistitems in dual-pane mode there will often be an
open game. Don't hold up the whole process by first waiting 1 second
to get a lock that's unavailable. Instead check if there's a JNIThread
instance available and if so use its lock to get the summary. Required
fixing JNIThread to not crash trying to save when released too early.
This commit is contained in:
Eric House 2016-07-26 07:44:21 -07:00
parent 272f8a3960
commit bc9b8466f5
2 changed files with 20 additions and 14 deletions

View file

@ -351,26 +351,30 @@ public class GameListItem extends LinearLayout
@Override
protected GameSummary doInBackground( Void... unused )
{
return DBUtils.getSummary( m_context, m_rowid, SUMMARY_WAIT_MSECS );
GameSummary result = null;
JNIThread thread = JNIThread.getRetained( m_rowid );
if ( null != thread ) {
GameLock lock = thread.getLock();
if ( null != lock ) {
result = DBUtils.getSummary( m_context, lock );
}
thread.release( false );
}
if ( null == result ) {
result = DBUtils.getSummary( m_context, m_rowid, SUMMARY_WAIT_MSECS );
}
return result;
} // doInBackground
@Override
protected void onPostExecute( GameSummary summary )
{
if ( 0 == --m_loadingCount ) {
if ( null == summary ) {
// Try again. Maybe it's open
JNIThread thread = JNIThread.getRetained( m_rowid );
if ( null != thread ) {
summary = DBUtils.getSummary( m_context,
thread.getLock() );
thread.release();
}
}
m_summary = summary;
boolean expanded = DBUtils.getExpanded( m_context, m_rowid );
boolean expanded = DBUtils.getExpanded( m_context, m_rowid );
makeThumbnailIf( expanded );
setData( summary, expanded );

View file

@ -752,7 +752,9 @@ public class JNIThread extends Thread {
return this;
}
public void release()
public void release() { release( true ); }
public void release( boolean save )
{
boolean stop = false;
synchronized( s_instances ) {
@ -766,7 +768,7 @@ public class JNIThread extends Thread {
if ( stop ) {
waitToStop( true );
} else if ( null != m_lastSavedState ) { // has configure() run?
} else if ( save && null != m_lastSavedState ) { // has configure() run?
handle( JNICmd.CMD_SAVE ); // in case releaser has made changes
}
}