Improve thread safety.

This commit is contained in:
lotodore
2011-01-12 23:35:45 +00:00
parent b6c820718a
commit 2a7456998a
10 changed files with 51 additions and 39 deletions
+12 -4
View File
@@ -36,10 +36,6 @@ public:
virtual PlayerList getActivePlayerList() const =0; virtual PlayerList getActivePlayerList() const =0;
virtual PlayerList getRunningPlayerList() const =0; virtual PlayerList getRunningPlayerList() const =0;
virtual PlayerListIterator getSeatIt(unsigned) const =0;
virtual PlayerListIterator getActivePlayerIt(unsigned) const =0;
virtual PlayerListIterator getRunningPlayerIt(unsigned) const =0;
virtual boost::shared_ptr<BoardInterface> getBoard() const =0; virtual boost::shared_ptr<BoardInterface> getBoard() const =0;
virtual boost::shared_ptr<BeRoInterface> getPreflop() const =0; virtual boost::shared_ptr<BeRoInterface> getPreflop() const =0;
virtual boost::shared_ptr<BeRoInterface> getFlop() const =0; virtual boost::shared_ptr<BeRoInterface> getFlop() const =0;
@@ -83,6 +79,18 @@ public:
virtual void switchRounds() =0; virtual void switchRounds() =0;
protected:
virtual PlayerListIterator getSeatIt(unsigned) const =0;
virtual PlayerListIterator getActivePlayerIt(unsigned) const =0;
virtual PlayerListIterator getRunningPlayerIt(unsigned) const =0;
friend class Game;
friend class LocalBeRo;
friend class LocalBeRoPreflop;
friend class LocalBeRoFlop;
friend class LocalBeRoTurn;
friend class LocalBeRoRiver;
friend class LocalBeRoPostRiver;
}; };
#endif #endif
+4 -4
View File
@@ -42,10 +42,6 @@ public:
PlayerList getActivePlayerList() const {return activePlayerList;} PlayerList getActivePlayerList() const {return activePlayerList;}
PlayerList getRunningPlayerList() const {return runningPlayerList;} PlayerList getRunningPlayerList() const {return runningPlayerList;}
PlayerListIterator getSeatIt(unsigned) const;
PlayerListIterator getActivePlayerIt(unsigned) const;
PlayerListIterator getRunningPlayerIt(unsigned) const;
boost::shared_ptr<BoardInterface> getBoard() const { return myBoard; } boost::shared_ptr<BoardInterface> getBoard() const { return myBoard; }
boost::shared_ptr<BeRoInterface> getPreflop() const { return myBeRo[GAME_STATE_PREFLOP]; } boost::shared_ptr<BeRoInterface> getPreflop() const { return myBeRo[GAME_STATE_PREFLOP]; }
boost::shared_ptr<BeRoInterface> getFlop() const { return myBeRo[GAME_STATE_FLOP]; } boost::shared_ptr<BeRoInterface> getFlop() const { return myBeRo[GAME_STATE_FLOP]; }
@@ -91,6 +87,10 @@ public:
void switchRounds(); void switchRounds();
protected:
PlayerListIterator getSeatIt(unsigned) const;
PlayerListIterator getActivePlayerIt(unsigned) const;
PlayerListIterator getRunningPlayerIt(unsigned) const;
private: private:
+2
View File
@@ -103,6 +103,7 @@ ClientBeRo::setSmallBlindPositionId(unsigned theValue)
unsigned unsigned
ClientBeRo::getSmallBlindPositionId() const ClientBeRo::getSmallBlindPositionId() const
{ {
boost::recursive_mutex::scoped_lock lock(m_syncMutex);
return smallBlindPositionId; return smallBlindPositionId;
} }
@@ -116,6 +117,7 @@ ClientBeRo::setBigBlindPositionId(unsigned theValue)
unsigned unsigned
ClientBeRo::getBigBlindPositionId() const ClientBeRo::getBigBlindPositionId() const
{ {
boost::recursive_mutex::scoped_lock lock(m_syncMutex);
return bigBlindPositionId; return bigBlindPositionId;
} }
+1 -8
View File
@@ -24,7 +24,7 @@
using namespace std; using namespace std;
ClientBoard::ClientBoard(unsigned dp) ClientBoard::ClientBoard(unsigned dp)
: currentHand(0), pot(0), sets(0), dealerPosition(dp) : pot(0), sets(0), dealerPosition(dp)
{ {
myCards[0] = myCards[1] = myCards[2] = myCards[3] = myCards[4] = 0; myCards[0] = myCards[1] = myCards[2] = myCards[3] = myCards[4] = 0;
} }
@@ -43,13 +43,6 @@ ClientBoard::setPlayerLists(PlayerList sl, PlayerList apl, PlayerList rpl)
runningPlayerList = rpl; runningPlayerList = rpl;
} }
void
ClientBoard::setHand(HandInterface* br)
{
boost::recursive_mutex::scoped_lock lock(m_syncMutex);
currentHand = br;
}
void void
ClientBoard::setMyCards(int* theValue) ClientBoard::setMyCards(int* theValue)
{ {
-3
View File
@@ -35,7 +35,6 @@ public:
~ClientBoard(); ~ClientBoard();
void setPlayerLists(PlayerList, PlayerList, PlayerList); void setPlayerLists(PlayerList, PlayerList, PlayerList);
void setHand(HandInterface*);
void setMyCards(int* theValue); void setMyCards(int* theValue);
void getMyCards(int* theValue); void getMyCards(int* theValue);
@@ -67,8 +66,6 @@ private:
PlayerList activePlayerList; PlayerList activePlayerList;
PlayerList runningPlayerList; PlayerList runningPlayerList;
HandInterface *currentHand;
std::list<unsigned> winners; std::list<unsigned> winners;
std::list<unsigned> playerNeedToShowCards; std::list<unsigned> playerNeedToShowCards;
+8
View File
@@ -68,24 +68,28 @@ ClientHand::start()
PlayerList PlayerList
ClientHand::getSeatsList() const ClientHand::getSeatsList() const
{ {
boost::recursive_mutex::scoped_lock lock(m_syncMutex);
return seatsList; return seatsList;
} }
PlayerList PlayerList
ClientHand::getActivePlayerList() const ClientHand::getActivePlayerList() const
{ {
boost::recursive_mutex::scoped_lock lock(m_syncMutex);
return activePlayerList; return activePlayerList;
} }
PlayerList PlayerList
ClientHand::getRunningPlayerList() const ClientHand::getRunningPlayerList() const
{ {
boost::recursive_mutex::scoped_lock lock(m_syncMutex);
return runningPlayerList; return runningPlayerList;
} }
PlayerListIterator PlayerListIterator
ClientHand::getSeatIt(unsigned uniqueId) const ClientHand::getSeatIt(unsigned uniqueId) const
{ {
boost::recursive_mutex::scoped_lock lock(m_syncMutex);
PlayerListIterator it; PlayerListIterator it;
for(it=seatsList->begin(); it!=seatsList->end(); it++) { for(it=seatsList->begin(); it!=seatsList->end(); it++) {
@@ -100,6 +104,7 @@ ClientHand::getSeatIt(unsigned uniqueId) const
PlayerListIterator PlayerListIterator
ClientHand::getActivePlayerIt(unsigned uniqueId) const ClientHand::getActivePlayerIt(unsigned uniqueId) const
{ {
boost::recursive_mutex::scoped_lock lock(m_syncMutex);
PlayerListIterator it; PlayerListIterator it;
for(it=activePlayerList->begin(); it!=activePlayerList->end(); it++) { for(it=activePlayerList->begin(); it!=activePlayerList->end(); it++) {
@@ -114,6 +119,7 @@ ClientHand::getActivePlayerIt(unsigned uniqueId) const
PlayerListIterator PlayerListIterator
ClientHand::getRunningPlayerIt(unsigned uniqueId) const ClientHand::getRunningPlayerIt(unsigned uniqueId) const
{ {
boost::recursive_mutex::scoped_lock lock(m_syncMutex);
PlayerListIterator it; PlayerListIterator it;
for(it=runningPlayerList->begin(); it!=runningPlayerList->end(); it++) { for(it=runningPlayerList->begin(); it!=runningPlayerList->end(); it++) {
@@ -297,12 +303,14 @@ ClientHand::getLastPlayersTurn() const
void void
ClientHand::setLastActionPlayer (unsigned theValue) ClientHand::setLastActionPlayer (unsigned theValue)
{ {
boost::recursive_mutex::scoped_lock lock(m_syncMutex);
lastActionPlayer = theValue; lastActionPlayer = theValue;
} }
unsigned unsigned
ClientHand::getLastActionPlayer() const ClientHand::getLastActionPlayer() const
{ {
boost::recursive_mutex::scoped_lock lock(m_syncMutex);
return lastActionPlayer; return lastActionPlayer;
} }
+5 -4
View File
@@ -42,10 +42,6 @@ class ClientHand : public HandInterface
PlayerList getActivePlayerList() const; PlayerList getActivePlayerList() const;
PlayerList getRunningPlayerList() const; PlayerList getRunningPlayerList() const;
PlayerListIterator getSeatIt(unsigned) const;
PlayerListIterator getActivePlayerIt(unsigned) const;
PlayerListIterator getRunningPlayerIt(unsigned) const;
boost::shared_ptr<BoardInterface> getBoard() const; boost::shared_ptr<BoardInterface> getBoard() const;
boost::shared_ptr<BeRoInterface> getPreflop() const; boost::shared_ptr<BeRoInterface> getPreflop() const;
boost::shared_ptr<BeRoInterface> getFlop() const; boost::shared_ptr<BeRoInterface> getFlop() const;
@@ -92,6 +88,11 @@ class ClientHand : public HandInterface
void switchRounds(); void switchRounds();
protected:
PlayerListIterator getSeatIt(unsigned) const;
PlayerListIterator getActivePlayerIt(unsigned) const;
PlayerListIterator getRunningPlayerIt(unsigned) const;
private: private:
mutable boost::recursive_mutex m_syncMutex; mutable boost::recursive_mutex m_syncMutex;
+3
View File
@@ -1732,6 +1732,9 @@ ClientStateWaitHand::InternalHandlePacket(boost::shared_ptr<ClientThread> client
cardDataStream >> myCards[0]; cardDataStream >> myCards[0];
cardDataStream >> myCards[1]; cardDataStream >> myCards[1];
} }
// Basic synchronisation before a new hand is started.
client->GetGui().waitForGuiUpdateDone();
// Start new hand.
client->GetGame()->getSeatsList()->front()->setMyCards(myCards); client->GetGame()->getSeatsList()->front()->setMyCards(myCards);
client->GetGame()->initHand(); client->GetGame()->initHand();
client->GetGame()->getCurrentHand()->setSmallBlind(netHandStart->smallBlind); client->GetGame()->getCurrentHand()->setSmallBlind(netHandStart->smallBlind);
+1 -1
View File
@@ -1219,7 +1219,7 @@ void
ClientThread::RemoveDisconnectedPlayers() ClientThread::RemoveDisconnectedPlayers()
{ {
// This should only be called between hands. // This should only be called between hands.
if (m_game.get()) if (m_game)
{ {
PlayerListIterator it; PlayerListIterator it;
for (it = m_game->getSeatsList()->begin(); it != m_game->getSeatsList()->end(); it++) for (it = m_game->getSeatsList()->begin(); it != m_game->getSeatsList()->end(); it++)