mirror of
https://github.com/glest/glest-source.git
synced 2025-08-21 23:45:14 +02:00
updating pathfinder mutexes to ensure safety of shared access to precache buffers
This commit is contained in:
@@ -602,16 +602,24 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
|
|||||||
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
||||||
MutexSafeWrapper safeMutex2(faction.getMutex(),mutexOwnerId);
|
MutexSafeWrapper safeMutex2(faction.getMutex(),mutexOwnerId);
|
||||||
|
|
||||||
if(faction.precachedTravelState.find(unit->getId()) != faction.precachedTravelState.end()) {
|
MutexSafeWrapper safeMutexPrecache(faction.getMutexPreCache(),mutexOwnerId);
|
||||||
|
bool foundPrecacheTravelState = (faction.precachedTravelState.find(unit->getId()) != faction.precachedTravelState.end());
|
||||||
|
safeMutexPrecache.ReleaseLock(true);
|
||||||
|
|
||||||
|
if(foundPrecacheTravelState == true) {
|
||||||
codeLocation = "7";
|
codeLocation = "7";
|
||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) {
|
// if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) {
|
||||||
char szBuf[8096]="";
|
// char szBuf[8096]="";
|
||||||
snprintf(szBuf,8096,"factions[unitFactionIndex].precachedTravelState[unit->getId()]: %d",faction.precachedTravelState[unit->getId()]);
|
// snprintf(szBuf,8096,"factions[unitFactionIndex].precachedTravelState[unit->getId()]: %d",faction.precachedTravelState[unit->getId()]);
|
||||||
unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
|
// unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
|
||||||
}
|
// }
|
||||||
|
|
||||||
if(faction.precachedTravelState[unit->getId()] == tsMoving) {
|
safeMutexPrecache.Lock();
|
||||||
|
bool foundPrecacheTravelStateIsMoving = (faction.precachedTravelState[unit->getId()] == tsMoving);
|
||||||
|
safeMutexPrecache.ReleaseLock(true);
|
||||||
|
|
||||||
|
if(foundPrecacheTravelStateIsMoving == true) {
|
||||||
codeLocation = "8";
|
codeLocation = "8";
|
||||||
bool canMoveToCells = true;
|
bool canMoveToCells = true;
|
||||||
|
|
||||||
@@ -665,13 +673,14 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
|
|||||||
codeLocation = "16";
|
codeLocation = "16";
|
||||||
unit->setUsePathfinderExtendedMaxNodes(false);
|
unit->setUsePathfinderExtendedMaxNodes(false);
|
||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) {
|
// if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) {
|
||||||
char szBuf[8096]="";
|
// char szBuf[8096]="";
|
||||||
snprintf(szBuf,8096,"return factions[unitFactionIndex].precachedTravelState[unit->getId()];");
|
// snprintf(szBuf,8096,"return factions[unitFactionIndex].precachedTravelState[unit->getId()];");
|
||||||
unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
|
// unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
|
||||||
}
|
// }
|
||||||
|
|
||||||
codeLocation = "17";
|
codeLocation = "17";
|
||||||
|
safeMutexPrecache.Lock();
|
||||||
return faction.precachedTravelState[unit->getId()];
|
return faction.precachedTravelState[unit->getId()];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -682,18 +691,23 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
|
|||||||
else {
|
else {
|
||||||
codeLocation = "19";
|
codeLocation = "19";
|
||||||
|
|
||||||
if(faction.precachedTravelState[unit->getId()] == tsBlocked) {
|
safeMutexPrecache.Lock();
|
||||||
|
bool foundPrecacheTravelStateIsBlocked = (faction.precachedTravelState[unit->getId()] == tsBlocked);
|
||||||
|
safeMutexPrecache.ReleaseLock(true);
|
||||||
|
|
||||||
|
if(foundPrecacheTravelStateIsBlocked == true) {
|
||||||
codeLocation = "20";
|
codeLocation = "20";
|
||||||
path->incBlockCount();
|
path->incBlockCount();
|
||||||
unit->setUsePathfinderExtendedMaxNodes(false);
|
unit->setUsePathfinderExtendedMaxNodes(false);
|
||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) {
|
// if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) {
|
||||||
char szBuf[8096]="";
|
// char szBuf[8096]="";
|
||||||
snprintf(szBuf,8096,"return factions[unitFactionIndex].precachedTravelState[unit->getId()];");
|
// snprintf(szBuf,8096,"return factions[unitFactionIndex].precachedTravelState[unit->getId()];");
|
||||||
unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
|
// unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
|
||||||
}
|
// }
|
||||||
|
|
||||||
codeLocation = "21";
|
codeLocation = "21";
|
||||||
|
safeMutexPrecache.Lock();
|
||||||
return faction.precachedTravelState[unit->getId()];
|
return faction.precachedTravelState[unit->getId()];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1062,6 +1076,11 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
|
|||||||
|
|
||||||
if(frameIndex >= 0) {
|
if(frameIndex >= 0) {
|
||||||
codeLocation = "61";
|
codeLocation = "61";
|
||||||
|
|
||||||
|
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
||||||
|
FactionState &faction = factions.getFactionState(factionIndex);
|
||||||
|
MutexSafeWrapper safeMutexPrecache(faction.getMutexPreCache(),mutexOwnerId);
|
||||||
|
|
||||||
faction.precachedTravelState[unit->getId()] = ts;
|
faction.precachedTravelState[unit->getId()] = ts;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Reference in New Issue
Block a user