- more usage of multi read single write mutex locking

This commit is contained in:
Mark Vejvoda
2011-11-26 09:00:57 +00:00
parent 6c1c248d62
commit 7fb7b5e611
2 changed files with 81 additions and 43 deletions

View File

@@ -169,7 +169,8 @@ ServerInterface::~ServerInterface() {
exitServer = true;
for(int i= 0; i < GameConstants::maxPlayers; ++i) {
if(slots[i] != NULL) {
MutexSafeWrapper safeMutex(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
//MutexSafeWrapper safeMutex(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],false,CODE_AT_LINE_X(i));
delete slots[i];
slots[i]=NULL;
}
@@ -203,7 +204,8 @@ int ServerInterface::isValidClientType(uint32 clientIp) {
int result = 0;
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
if(slots[i] != NULL) {
MutexSafeWrapper safeMutex(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
//MutexSafeWrapper safeMutex(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
Socket *socket = slots[i]->getSocket();
if(socket != NULL) {
@@ -232,7 +234,10 @@ void ServerInterface::addSlot(int playerIndex) {
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[playerIndex],CODE_AT_LINE_X(playerIndex));
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[playerIndex],CODE_AT_LINE_X(playerIndex));
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[playerIndex],false,CODE_AT_LINE_X(i));
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
ConnectionSlot *slot = slots[playerIndex];
if(slot != NULL) {
@@ -240,7 +245,7 @@ void ServerInterface::addSlot(int playerIndex) {
}
slots[playerIndex] = new ConnectionSlot(this, playerIndex);
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
safeMutexSlot.ReleaseLock();
safeRWL.ReleaseLock();
delete slot;
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
safeMutex.ReleaseLock();
@@ -259,8 +264,12 @@ bool ServerInterface::switchSlot(int fromPlayerIndex, int toPlayerIndex) {
}
MutexSafeWrapper safeMutex(&serverSynchAccessor,CODE_AT_LINE);
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[fromPlayerIndex],CODE_AT_LINE_X(fromPlayerIndex));
MutexSafeWrapper safeMutexSlot2(&slotAccessorMutexes[toPlayerIndex],CODE_AT_LINE_X(toPlayerIndex));
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[fromPlayerIndex],CODE_AT_LINE_X(fromPlayerIndex));
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[fromPlayerIndex],false,CODE_AT_LINE_X(i));
//MutexSafeWrapper safeMutexSlot2(&slotAccessorMutexes[toPlayerIndex],CODE_AT_LINE_X(toPlayerIndex));
ReadWriteMutexSafeWrapper safeRWL2(&slotAccessorMutexes[toPlayerIndex],false,CODE_AT_LINE_X(i));
if(slots[toPlayerIndex] != NULL && slots[toPlayerIndex] != NULL &&
slots[toPlayerIndex]->isConnected() == false) {
slots[fromPlayerIndex]->setPlayerIndex(toPlayerIndex);
@@ -271,14 +280,14 @@ bool ServerInterface::switchSlot(int fromPlayerIndex, int toPlayerIndex) {
safeMutex.ReleaseLock();
PlayerIndexMessage playerIndexMessage(toPlayerIndex);
slots[toPlayerIndex]->sendMessage(&playerIndexMessage);
safeMutexSlot.ReleaseLock();
safeMutexSlot2.ReleaseLock();
safeRWL.ReleaseLock();
safeRWL2.ReleaseLock();
result = true;
updateListen();
}
else {
safeMutexSlot.ReleaseLock();
safeMutexSlot2.ReleaseLock();
safeRWL.ReleaseLock();
safeRWL2.ReleaseLock();
safeMutex.ReleaseLock();
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@@ -289,10 +298,11 @@ void ServerInterface::removeSlot(int playerIndex, int lockedSlotIndex) {
Lang &lang= Lang::getInstance();
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex);
MutexSafeWrapper safeMutex(&serverSynchAccessor,CODE_AT_LINE);
MutexSafeWrapper safeMutexSlot(NULL,CODE_AT_LINE_X(playerIndex));
//MutexSafeWrapper safeMutexSlot(NULL,CODE_AT_LINE_X(playerIndex));
ReadWriteMutexSafeWrapper safeRWL(NULL,false,CODE_AT_LINE_X(i));
if(playerIndex != lockedSlotIndex) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex);
safeMutexSlot.setMutex(&slotAccessorMutexes[playerIndex],CODE_AT_LINE_X(playerIndex));
safeRWL.setReadWriteMutex(&slotAccessorMutexes[playerIndex],false,CODE_AT_LINE_X(playerIndex));
}
ConnectionSlot *slot = slots[playerIndex];
bool notifyDisconnect = false;
@@ -324,7 +334,7 @@ void ServerInterface::removeSlot(int playerIndex, int lockedSlotIndex) {
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex);
slots[playerIndex]= NULL;
safeMutexSlot.ReleaseLock();
safeRWL.ReleaseLock();
safeMutex.ReleaseLock();
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex);
delete slot;
@@ -346,14 +356,16 @@ void ServerInterface::removeSlot(int playerIndex, int lockedSlotIndex) {
}
ConnectionSlot *ServerInterface::getSlot(int playerIndex) {
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[playerIndex],CODE_AT_LINE_X(i));
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[playerIndex],CODE_AT_LINE_X(i));
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[playerIndex],true,CODE_AT_LINE_X(i));
ConnectionSlot *result = slots[playerIndex];
return result;
}
bool ServerInterface::isClientConnected(int index) {
bool result = false;
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[index],CODE_AT_LINE_X(i));
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[index],CODE_AT_LINE_X(i));
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[index],true,CODE_AT_LINE_X(i));
if(slots[index] != NULL && slots[index]->isConnected() == true) {
result = true;
}
@@ -374,7 +386,8 @@ bool ServerInterface::hasClientConnection() {
int ServerInterface::getConnectedSlotCount() {
int connectedSlotCount = 0;
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
if(slots[i] != NULL) {
++connectedSlotCount;
}
@@ -656,7 +669,8 @@ bool ServerInterface::signalClientReceiveCommands(ConnectionSlot *connectionSlot
void ServerInterface::updateSocketTriggeredList(std::map<PLATFORM_SOCKET,bool> & socketTriggeredList) {
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
ConnectionSlot* connectionSlot= slots[i];
if(connectionSlot != NULL) {
PLATFORM_SOCKET clientSocket = connectionSlot->getSocketId();
@@ -669,7 +683,8 @@ void ServerInterface::updateSocketTriggeredList(std::map<PLATFORM_SOCKET,bool> &
void ServerInterface::validateConnectedClients() {
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
ConnectionSlot* connectionSlot = slots[i];
if(connectionSlot != NULL) {
connectionSlot->validateConnection();
@@ -682,7 +697,8 @@ void ServerInterface::signalClientsToRecieveData(std::map<PLATFORM_SOCKET,bool>
std::map<int,bool> & mapSlotSignalledList) {
//bool checkForNewClients = true;
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
ConnectionSlot* connectionSlot = slots[i];
bool socketTriggered = false;
@@ -712,7 +728,8 @@ void ServerInterface::checkForCompletedClients(std::map<int,bool> & mapSlotSigna
//printf("===> START slot %d [%p] - About to checkForCompletedClients\n",i,slots[i]);
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
//printf("===> IN slot %d - About to checkForCompletedClients\n",i);
@@ -772,7 +789,8 @@ void ServerInterface::checkForLaggingClients(std::map<int,bool> &mapSlotSignalle
threadsDone = true;
// Examine all threads for completion of delegation
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
ConnectionSlot* connectionSlot = slots[i];
if(connectionSlot != NULL && mapSlotSignalledList[i] == true &&
slotsCompleted.find(i) == slotsCompleted.end()) {
@@ -889,7 +907,8 @@ void ServerInterface::checkForLaggingClients(std::vector <string> &errorMsgList)
std::map<int,bool> slotsWarnedList;
// Examine all threads for completion of delegation
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
ConnectionSlot* connectionSlot = slots[i];
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
@@ -932,7 +951,8 @@ void ServerInterface::checkForLaggingClients(std::vector <string> &errorMsgList)
void ServerInterface::executeNetworkCommandsFromClients() {
if(gameHasBeenInitiated == true) {
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
ConnectionSlot* connectionSlot= slots[i];
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
vector<NetworkCommand> pendingList = connectionSlot->getPendingNetworkCommandList(true);
@@ -949,7 +969,8 @@ void ServerInterface::executeNetworkCommandsFromClients() {
void ServerInterface::dispatchPendingChatMessages(std::vector <string> &errorMsgList) {
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
ConnectionSlot* connectionSlot= slots[i];
if(connectionSlot != NULL &&
connectionSlot->getChatTextList(false).empty() == false) {
@@ -998,13 +1019,14 @@ void ServerInterface::dispatchPendingChatMessages(std::vector <string> &errorMsg
void ServerInterface::waitForSignalledClients(std::map<int,bool> &mapSlotSignalledList,std::vector <string> &errorMsgList) {
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
if(mapSlotSignalledList[i] == true) {
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
ConnectionSlot* connectionSlot= slots[i];
safeMutexSlot.ReleaseLock(true);
safeRWL.ReleaseLock(true);
if(connectionSlot != NULL) {
connectionSlot->waitSlotWorkerTaskCompleted(4000);
safeMutexSlot.Lock();
safeRWL.Lock();
connectionSlot= slots[i];
if(connectionSlot != NULL) {
std::vector<std::string> errorList = connectionSlot->getThreadErrorList();
@@ -1019,7 +1041,7 @@ void ServerInterface::waitForSignalledClients(std::map<int,bool> &mapSlotSignall
connectionSlot->clearThreadErrorList();
}
}
safeMutexSlot.ReleaseLock();
safeRWL.ReleaseLock();
}
}
}
@@ -1313,7 +1335,8 @@ void ServerInterface::waitUntilReady(Checksum *checksum) {
vector<string> waitingForHosts;
allReady= true;
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
ConnectionSlot* connectionSlot= slots[i];
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
if(connectionSlot->isReady() == false) {
@@ -1392,7 +1415,8 @@ void ServerInterface::waitUntilReady(Checksum *checksum) {
uint32 loadingStatus = nmls_NONE;
//send ready message after, so clients start delayed
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
ConnectionSlot* connectionSlot= slots[i];
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
switch(i) {
@@ -1450,7 +1474,8 @@ void ServerInterface::waitUntilReady(Checksum *checksum) {
// send loading status message
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
ConnectionSlot* connectionSlot= slots[i];
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
NetworkMessageLoadingStatus networkMessageLoadingStatus(loadingStatus);
@@ -1486,7 +1511,8 @@ void ServerInterface::waitUntilReady(Checksum *checksum) {
try {
//send ready message after, so clients start delayed
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
ConnectionSlot* connectionSlot= slots[i];
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
NetworkMessageReady networkMessageReady(checksum->getSum());
@@ -1582,7 +1608,8 @@ string ServerInterface::getNetworkStatus() {
Lang &lang = Lang::getInstance();
string str="";
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
ConnectionSlot* connectionSlot= slots[i];
str+= intToStr(i)+ ": ";
@@ -1611,7 +1638,8 @@ bool ServerInterface::launchGame(const GameSettings *gameSettings) {
bool bOkToStart = true;
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
ConnectionSlot *connectionSlot= slots[i];
if(connectionSlot != NULL &&
(connectionSlot->getAllowDownloadDataSynch() == true || connectionSlot->getAllowGameDataSynchCheck() == true) &&
@@ -1631,7 +1659,8 @@ bool ServerInterface::launchGame(const GameSettings *gameSettings) {
if(useInGameBlockingClientSockets == true) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
for(int i= 0; i < GameConstants::maxPlayers; ++i) {
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
ConnectionSlot *connectionSlot= slots[i];
if(connectionSlot != NULL && connectionSlot->isConnected()) {
connectionSlot->getSocket()->setBlock(true);
@@ -1709,10 +1738,11 @@ void ServerInterface::broadcastMessage(const NetworkMessage *networkMessage, int
}
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
MutexSafeWrapper safeMutexSlot(NULL,CODE_AT_LINE_X(i));
//MutexSafeWrapper safeMutexSlot(NULL,CODE_AT_LINE_X(i));
ReadWriteMutexSafeWrapper safeRWL(NULL,true,CODE_AT_LINE_X(i));
if(i != lockedSlotIndex) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] i = %d, lockedSlotIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,i,lockedSlotIndex);
safeMutexSlot.setMutex(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
safeRWL.setReadWriteMutex(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
}
ConnectionSlot* connectionSlot= slots[i];
@@ -1760,7 +1790,8 @@ void ServerInterface::broadcastMessageToConnectedClients(const NetworkMessage *n
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
try {
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
ConnectionSlot *connectionSlot= slots[i];
if(i != excludeSlot && connectionSlot != NULL) {
@@ -1785,6 +1816,7 @@ void ServerInterface::updateListen() {
int openSlotCount = 0;
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],intToStr(__LINE__) + "_" + intToStr(i));
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
bool isSlotOpen = (slots[i] != NULL && slots[i]->isConnected() == false);
if(isSlotOpen == true) {
@@ -1798,6 +1830,7 @@ int ServerInterface::getOpenSlotCount() {
int openSlotCount = 0;
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],intToStr(__LINE__) + "_" + intToStr(i));
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
bool isSlotOpen = (slots[i] != NULL && slots[i]->isConnected() == false);
if(isSlotOpen == true) {
@@ -1857,7 +1890,8 @@ void ServerInterface::setGameSettings(GameSettings *serverGameSettings, bool wai
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
//printf("===> START slot %d - About to setGameSettings #1\n",i);
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
ConnectionSlot *connectionSlot = slots[i];
if(connectionSlot != NULL && connectionSlot->isConnected()) {
if(connectionSlot->getReceivedNetworkGameStatus() == false) {
@@ -1873,7 +1907,8 @@ void ServerInterface::setGameSettings(GameSettings *serverGameSettings, bool wai
}
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
ConnectionSlot *connectionSlot = slots[i];
if(connectionSlot != NULL && connectionSlot->isConnected()) {
connectionSlot->setReceivedNetworkGameStatus(false);
@@ -1893,7 +1928,8 @@ void ServerInterface::setGameSettings(GameSettings *serverGameSettings, bool wai
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
//printf("===> START slot %d - About to setGameSettings 2\n",i);
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
ConnectionSlot *connectionSlot = slots[i];
if(connectionSlot != NULL && connectionSlot->isConnected()) {
if(connectionSlot->getReceivedNetworkGameStatus() == false) {
@@ -1944,7 +1980,8 @@ std::map<string,string> ServerInterface::publishToMasterserver() {
std::map < string, string > publishToServerInfo;
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
if(slots[i] != NULL) {
slotCountUsed++;
slotCountHumans++;

View File

@@ -48,7 +48,8 @@ public:
private:
ConnectionSlot* slots[GameConstants::maxPlayers];
Mutex slotAccessorMutexes[GameConstants::maxPlayers];
//Mutex slotAccessorMutexes[GameConstants::maxPlayers];
ReadWriteMutex slotAccessorMutexes[GameConstants::maxPlayers];
ServerSocket serverSocket;
bool gameHasBeenInitiated;