mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-03 23:04:08 +01:00
move use of JNIThread's lock into getSummary()
Rather than have callers of getSummary() try JNIThread for the lock, do that check inside getSummary(), and move it to GameUtils from DBUtils since it's using higher-level knowledge now.
This commit is contained in:
parent
3baeb79a45
commit
16d6b7cccc
7 changed files with 45 additions and 43 deletions
|
@ -2592,7 +2592,7 @@ public class BoardDelegate extends DelegateBase
|
|||
|
||||
public static boolean rematchSupported( Context context, long rowID )
|
||||
{
|
||||
GameSummary summary = DBUtils.getSummary( context, rowID, 1 );
|
||||
GameSummary summary = GameUtils.getSummary( context, rowID, 1 );
|
||||
return null != summary && rematchSupported( null, summary );
|
||||
}
|
||||
|
||||
|
|
|
@ -116,27 +116,6 @@ public class DBUtils {
|
|||
public int[] m_counts;
|
||||
}
|
||||
|
||||
public static GameSummary getSummary( Context context, long rowid,
|
||||
long maxMillis )
|
||||
{
|
||||
GameSummary result = null;
|
||||
try {
|
||||
GameLock lock = new GameLock( rowid, false ).lock( maxMillis );
|
||||
if ( null != lock ) {
|
||||
result = getSummary( context, lock );
|
||||
lock.unlock();
|
||||
}
|
||||
} catch ( GameLock.GameLockedException gle ) {
|
||||
DbgUtils.loge( gle );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static GameSummary getSummary( Context context, long rowid )
|
||||
{
|
||||
return getSummary( context, rowid, 0L );
|
||||
}
|
||||
|
||||
public static GameSummary getSummary( Context context,
|
||||
GameLock lock )
|
||||
{
|
||||
|
@ -1125,6 +1104,9 @@ public class DBUtils {
|
|||
lock.unlock();
|
||||
} else {
|
||||
DbgUtils.logf( "deleteGame: unable to lock rowid %d", rowid );
|
||||
if ( BuildConfig.DEBUG ) {
|
||||
Assert.fail();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -351,21 +351,7 @@ public class GameListItem extends LinearLayout
|
|||
@Override
|
||||
protected GameSummary doInBackground( Void... unused )
|
||||
{
|
||||
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;
|
||||
return GameUtils.getSummary( m_context, m_rowid, SUMMARY_WAIT_MSECS );
|
||||
} // doInBackground
|
||||
|
||||
@Override
|
||||
|
|
|
@ -213,6 +213,38 @@ public class GameUtils {
|
|||
return result;
|
||||
}
|
||||
|
||||
public static GameSummary getSummary( Context context, long rowid,
|
||||
long maxMillis )
|
||||
{
|
||||
GameSummary result = null;
|
||||
JNIThread thread = JNIThread.getRetained( rowid );
|
||||
GameLock lock = null;
|
||||
if ( null != thread ) {
|
||||
lock = thread.getLock();
|
||||
} else {
|
||||
try {
|
||||
lock = new GameLock( rowid, false ).lock( maxMillis );
|
||||
} catch ( GameLock.GameLockedException gle ) {
|
||||
DbgUtils.loge( gle );
|
||||
}
|
||||
}
|
||||
|
||||
if ( null != lock ) {
|
||||
result = DBUtils.getSummary( context, lock );
|
||||
if ( null == thread ) {
|
||||
lock.unlock();
|
||||
} else {
|
||||
thread.release();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static GameSummary getSummary( Context context, long rowid )
|
||||
{
|
||||
return getSummary( context, rowid, 0L );
|
||||
}
|
||||
|
||||
public static long dupeGame( Context context, long rowidIn )
|
||||
{
|
||||
long rowid = DBUtils.ROWID_NOTFOUND;
|
||||
|
|
|
@ -711,7 +711,7 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
self.m_adapter.invalName( self.m_rowid );
|
||||
}
|
||||
};
|
||||
GameSummary summary = DBUtils.getSummary( m_activity, m_rowid );
|
||||
GameSummary summary = GameUtils.getSummary( m_activity, m_rowid );
|
||||
int labelID = (summary.isMultiGame() && !summary.anyMissing())
|
||||
? R.string.rename_label_caveat : R.string.rename_label;
|
||||
dialog = buildNamerDlg( GameUtils.getName( m_activity, m_rowid ),
|
||||
|
@ -1748,7 +1748,8 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
Action.NEW_FROM, selRowIDs[0] );
|
||||
break;
|
||||
case R.id.games_game_copy:
|
||||
final GameSummary smry = DBUtils.getSummary( m_activity, selRowIDs[0] );
|
||||
final GameSummary smry = GameUtils.getSummary( m_activity,
|
||||
selRowIDs[0] );
|
||||
if ( smry.inRelayGame() ) {
|
||||
showOKOnlyDialog( R.string.no_copy_network );
|
||||
} else {
|
||||
|
@ -1782,7 +1783,7 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
|
||||
// DEBUG only
|
||||
case R.id.games_game_invites:
|
||||
msg = DBUtils.getSummary( m_activity, selRowIDs[0] )
|
||||
msg = GameUtils.getSummary( m_activity, selRowIDs[0] )
|
||||
.conTypes.toString( m_activity );
|
||||
msg = getString( R.string.invites_net_fmt, msg );
|
||||
|
||||
|
|
|
@ -81,8 +81,8 @@ public class NagTurnReceiver extends BroadcastReceiver {
|
|||
boolean lastWarning = 0 == info.m_nextNag;
|
||||
|
||||
long rowid = info.m_rowid;
|
||||
GameSummary summary = DBUtils.getSummary( context, rowid,
|
||||
10 );
|
||||
GameSummary summary = GameUtils.getSummary( context, rowid,
|
||||
10 );
|
||||
String prevPlayer = null == summary
|
||||
? LocUtils.getString(context, R.string.prev_player)
|
||||
: summary.getPrevPlayer();
|
||||
|
|
|
@ -233,7 +233,7 @@ public class JNIThread extends Thread {
|
|||
public GamePtr getGamePtr() { return m_jniGamePtr; }
|
||||
public CurGameInfo getGI() { return m_gi; }
|
||||
public GameSummary getSummary() { return m_summary; }
|
||||
public GameLock getLock() { return m_lock; }
|
||||
public GameLock getLock() { Assert.assertNotNull(m_lock); return m_lock; }
|
||||
|
||||
private void waitToStop( boolean save )
|
||||
{
|
||||
|
@ -787,6 +787,7 @@ public class JNIThread extends Thread {
|
|||
result = s_instances.get( rowid );
|
||||
if ( null == result && makeNew ) {
|
||||
result = new JNIThread( new GameLock( rowid, true ).lock() );
|
||||
Assert.assertNotNull( result );
|
||||
s_instances.put( rowid, result );
|
||||
}
|
||||
if ( null != result ) {
|
||||
|
|
Loading…
Reference in a new issue