server mutex fix

This commit is contained in:
Max-Wilhelm Bruker 2011-04-21 02:04:15 +02:00
parent 38b31681e2
commit c4ba33dfeb
3 changed files with 12 additions and 3 deletions

View file

@ -51,7 +51,7 @@ Server_Game::~Server_Game()
QMapIterator<int, Server_Player *> playerIterator(players); QMapIterator<int, Server_Player *> playerIterator(players);
while (playerIterator.hasNext()) while (playerIterator.hasNext())
delete playerIterator.next().value(); playerIterator.next().value()->prepareDestroy();
players.clear(); players.clear();
room->removeGame(this); room->removeGame(this);
@ -243,7 +243,7 @@ void Server_Game::removePlayer(Server_Player *player)
sendGameEvent(new Event_Leave(player->getPlayerId())); sendGameEvent(new Event_Leave(player->getPlayerId()));
bool playerActive = activePlayer == player->getPlayerId(); bool playerActive = activePlayer == player->getPlayerId();
bool spectator = player->getSpectator(); bool spectator = player->getSpectator();
delete player; player->prepareDestroy();
if (!getPlayerCount()) if (!getPlayerCount())
deleteLater(); deleteLater();

View file

@ -16,17 +16,25 @@ Server_Player::Server_Player(Server_Game *_game, int _playerId, ServerInfo_User
} }
Server_Player::~Server_Player() Server_Player::~Server_Player()
{
}
void Server_Player::prepareDestroy()
{ {
QMutexLocker locker(&game->gameMutex); QMutexLocker locker(&game->gameMutex);
QMutexLocker locker2(&playerMutex);
delete deck; delete deck;
playerMutex.lock();
if (handler) if (handler)
handler->playerRemovedFromGame(game); handler->playerRemovedFromGame(game);
playerMutex.unlock();
delete userInfo; delete userInfo;
clearZones(); clearZones();
deleteLater();
} }
void Server_Player::moveToThread(QThread *thread) void Server_Player::moveToThread(QThread *thread)

View file

@ -43,6 +43,7 @@ private:
public: public:
Server_Player(Server_Game *_game, int _playerId, ServerInfo_User *_userInfo, bool _spectator, Server_ProtocolHandler *_handler); Server_Player(Server_Game *_game, int _playerId, ServerInfo_User *_userInfo, bool _spectator, Server_ProtocolHandler *_handler);
~Server_Player(); ~Server_Player();
void prepareDestroy();
void moveToThread(QThread *thread); void moveToThread(QThread *thread);
Server_ProtocolHandler *getProtocolHandler() const { return handler; } Server_ProtocolHandler *getProtocolHandler() const { return handler; }
void setProtocolHandler(Server_ProtocolHandler *_handler) { playerMutex.lock(); handler = _handler; playerMutex.unlock(); } void setProtocolHandler(Server_ProtocolHandler *_handler) { playerMutex.lock(); handler = _handler; playerMutex.unlock(); }