mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-01 19:57:11 +01:00
track current BoardActivity instance using HashSet rather than single instance since during transitions there can be two. Fixes asserts from recent commit.
This commit is contained in:
parent
0b132661ca
commit
5e3c26d453
1 changed files with 36 additions and 32 deletions
|
@ -53,6 +53,7 @@ import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.concurrent.Semaphore;
|
import java.util.concurrent.Semaphore;
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
|
|
||||||
|
@ -180,21 +181,20 @@ public class BoardActivity extends XWActivity
|
||||||
private boolean m_haveInvited = false;
|
private boolean m_haveInvited = false;
|
||||||
private boolean m_overNotShown;
|
private boolean m_overNotShown;
|
||||||
|
|
||||||
private static BoardActivity s_this = null;
|
private static HashSet<BoardActivity> s_this = new HashSet<BoardActivity>();
|
||||||
private static Class s_thisLocker = BoardActivity.class;
|
|
||||||
|
|
||||||
public static boolean feedMessage( int gameID, byte[] msg,
|
public static boolean feedMessage( int gameID, byte[] msg,
|
||||||
CommsAddrRec retAddr )
|
CommsAddrRec retAddr )
|
||||||
{
|
{
|
||||||
boolean delivered = false;
|
boolean delivered = false;
|
||||||
synchronized( s_thisLocker ) {
|
synchronized( s_this ) {
|
||||||
if ( null != s_this ) {
|
if ( 1 == s_this.size() ) {
|
||||||
Assert.assertNotNull( s_this.m_gi );
|
BoardActivity self = s_this.iterator().next();
|
||||||
Assert.assertNotNull( s_this.m_gameLock );
|
Assert.assertNotNull( self.m_gi );
|
||||||
Assert.assertNotNull( s_this.m_jniThread );
|
Assert.assertNotNull( self.m_gameLock );
|
||||||
if ( gameID == s_this.m_gi.gameID ) {
|
Assert.assertNotNull( self.m_jniThread );
|
||||||
s_this.m_jniThread.handle( JNICmd.CMD_RECEIVE, msg,
|
if ( gameID == self.m_gi.gameID ) {
|
||||||
retAddr );
|
self.m_jniThread.handle( JNICmd.CMD_RECEIVE, msg, retAddr );
|
||||||
delivered = true;
|
delivered = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -205,13 +205,14 @@ public class BoardActivity extends XWActivity
|
||||||
public static boolean feedMessage( long rowid, byte[] msg )
|
public static boolean feedMessage( long rowid, byte[] msg )
|
||||||
{
|
{
|
||||||
boolean delivered = false;
|
boolean delivered = false;
|
||||||
synchronized( s_thisLocker ) {
|
synchronized( s_this ) {
|
||||||
if ( null != s_this ) {
|
if ( 1 == s_this.size() ) {
|
||||||
Assert.assertNotNull( s_this.m_gi );
|
BoardActivity self = s_this.iterator().next();
|
||||||
Assert.assertNotNull( s_this.m_gameLock );
|
Assert.assertNotNull( self.m_gi );
|
||||||
Assert.assertNotNull( s_this.m_jniThread );
|
Assert.assertNotNull( self.m_gameLock );
|
||||||
if ( rowid == s_this.m_rowid ) {
|
Assert.assertNotNull( self.m_jniThread );
|
||||||
s_this.m_jniThread.handle( JNICmd.CMD_RECEIVE, msg, null );
|
if ( rowid == self.m_rowid ) {
|
||||||
|
self.m_jniThread.handle( JNICmd.CMD_RECEIVE, msg, null );
|
||||||
delivered = true;
|
delivered = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -223,15 +224,16 @@ public class BoardActivity extends XWActivity
|
||||||
{
|
{
|
||||||
boolean delivered = false;
|
boolean delivered = false;
|
||||||
Assert.assertNotNull( msgs );
|
Assert.assertNotNull( msgs );
|
||||||
synchronized( s_thisLocker ) {
|
synchronized( s_this ) {
|
||||||
if ( null != s_this ) {
|
if ( 1 == s_this.size() ) {
|
||||||
Assert.assertNotNull( s_this.m_gi );
|
BoardActivity self = s_this.iterator().next();
|
||||||
Assert.assertNotNull( s_this.m_gameLock );
|
Assert.assertNotNull( self.m_gi );
|
||||||
Assert.assertNotNull( s_this.m_jniThread );
|
Assert.assertNotNull( self.m_gameLock );
|
||||||
if ( rowid == s_this.m_rowid ) {
|
Assert.assertNotNull( self.m_jniThread );
|
||||||
|
if ( rowid == self.m_rowid ) {
|
||||||
delivered = true; // even if no messages!
|
delivered = true; // even if no messages!
|
||||||
for ( byte[] msg : msgs ) {
|
for ( byte[] msg : msgs ) {
|
||||||
s_this.m_jniThread.handle( JNICmd.CMD_RECEIVE, msg,
|
self.m_jniThread.handle( JNICmd.CMD_RECEIVE, msg,
|
||||||
null );
|
null );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -242,17 +244,19 @@ public class BoardActivity extends XWActivity
|
||||||
|
|
||||||
private static void setThis( BoardActivity self )
|
private static void setThis( BoardActivity self )
|
||||||
{
|
{
|
||||||
synchronized( s_thisLocker ) {
|
synchronized( s_this ) {
|
||||||
Assert.assertNull( s_this );
|
DbgUtils.logf( "setThis(self=%H)", self );
|
||||||
s_this = self;
|
Assert.assertTrue( !s_this.contains(self) ); // here
|
||||||
|
s_this.add( self );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void clearThis()
|
private static void clearThis( BoardActivity self )
|
||||||
{
|
{
|
||||||
synchronized( s_thisLocker ) {
|
synchronized( s_this ) {
|
||||||
Assert.assertNotNull( s_this );
|
DbgUtils.logf( "clearThis(s_this=%H)", s_this );
|
||||||
s_this = null;
|
Assert.assertTrue( s_this.contains( self ) );
|
||||||
|
s_this.remove( self );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2110,7 +2114,7 @@ public class BoardActivity extends XWActivity
|
||||||
}
|
}
|
||||||
m_view.stopHandling();
|
m_view.stopHandling();
|
||||||
|
|
||||||
clearThis();
|
clearThis( this );
|
||||||
|
|
||||||
if ( XWPrefs.getThumbEnabled( this ) ) {
|
if ( XWPrefs.getThumbEnabled( this ) ) {
|
||||||
// Before we dispose, and after JNIThread has
|
// Before we dispose, and after JNIThread has
|
||||||
|
|
Loading…
Add table
Reference in a new issue