lock around Game.cardSets, as this was causing concurrent modification exceptions. It would be ideal to allow concurrent reads and just require an exclusive write, but that is an excerise for later. Fixes #21.
This commit is contained in:
parent
c66ffa6e1f
commit
aa7b199bdb
|
@ -363,8 +363,10 @@ public class Game {
|
||||||
final Set<CardSet> cardSets1, final String password1) {
|
final Set<CardSet> cardSets1, final String password1) {
|
||||||
this.scoreGoal = scoreLimit;
|
this.scoreGoal = scoreLimit;
|
||||||
this.maxPlayers = playerLimit;
|
this.maxPlayers = playerLimit;
|
||||||
this.cardSets.clear();
|
synchronized (this.cardSets) {
|
||||||
this.cardSets.addAll(cardSets1);
|
this.cardSets.clear();
|
||||||
|
this.cardSets.addAll(cardSets1);
|
||||||
|
}
|
||||||
this.password = password1;
|
this.password = password1;
|
||||||
|
|
||||||
final HashMap<ReturnableData, Object> data = getEventMap();
|
final HashMap<ReturnableData, Object> data = getEventMap();
|
||||||
|
@ -397,9 +399,12 @@ public class Game {
|
||||||
info.put(GameInfo.ID, id);
|
info.put(GameInfo.ID, id);
|
||||||
info.put(GameInfo.HOST, host.toString());
|
info.put(GameInfo.HOST, host.toString());
|
||||||
info.put(GameInfo.STATE, state.toString());
|
info.put(GameInfo.STATE, state.toString());
|
||||||
final List<Integer> cardSetIds = new ArrayList<Integer>(cardSets.size());
|
final List<Integer> cardSetIds;
|
||||||
for (final CardSet cardSet : cardSets) {
|
synchronized (cardSets) {
|
||||||
cardSetIds.add(cardSet.getId());
|
cardSetIds = new ArrayList<Integer>(cardSets.size());
|
||||||
|
for (final CardSet cardSet : cardSets) {
|
||||||
|
cardSetIds.add(cardSet.getId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
info.put(GameInfo.CARD_SETS, cardSetIds);
|
info.put(GameInfo.CARD_SETS, cardSetIds);
|
||||||
info.put(GameInfo.PLAYER_LIMIT, maxPlayers);
|
info.put(GameInfo.PLAYER_LIMIT, maxPlayers);
|
||||||
|
@ -541,8 +546,10 @@ public class Game {
|
||||||
if (started) {
|
if (started) {
|
||||||
// do this stuff outside the players lock; they will lock players again later for much less
|
// do this stuff outside the players lock; they will lock players again later for much less
|
||||||
// time, and not at the same time as trying to lock users, which has caused deadlocks
|
// time, and not at the same time as trying to lock users, which has caused deadlocks
|
||||||
blackDeck = new BlackDeck(cardSets);
|
synchronized (cardSets) {
|
||||||
whiteDeck = new WhiteDeck(cardSets);
|
blackDeck = new BlackDeck(cardSets);
|
||||||
|
whiteDeck = new WhiteDeck(cardSets);
|
||||||
|
}
|
||||||
startNextRound();
|
startNextRound();
|
||||||
gameManager.broadcastGameListRefresh();
|
gameManager.broadcastGameListRefresh();
|
||||||
}
|
}
|
||||||
|
@ -550,9 +557,11 @@ public class Game {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasBaseDeck() {
|
public boolean hasBaseDeck() {
|
||||||
for (final CardSet cardSet : cardSets) {
|
synchronized (cardSets) {
|
||||||
if (cardSet.isBaseDeck()) {
|
for (final CardSet cardSet : cardSets) {
|
||||||
return true;
|
if (cardSet.isBaseDeck()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue