- attempt to fix hang issue reported by tomreyn

This commit is contained in:
Mark Vejvoda 2011-07-05 18:26:09 +00:00
parent 1f8d1b68eb
commit 1fd179196c
2 changed files with 11 additions and 4 deletions

View File

@ -877,6 +877,7 @@ Command *Unit::getCurrrentCommandThreadSafe() {
if(commands.empty() == false) { if(commands.empty() == false) {
return commands.front(); return commands.front();
} }
return NULL; return NULL;
} }
@ -1078,6 +1079,7 @@ CommandResult Unit::cancelCommand() {
this->unitPath->clear(); this->unitPath->clear();
safeMutex.ReleaseLock(); safeMutex.ReleaseLock();
return crSuccess; return crSuccess;
} }
@ -2087,6 +2089,7 @@ void Unit::clearCommands() {
delete commands.back(); delete commands.back();
commands.pop_back(); commands.pop_back();
} }
safeMutex.ReleaseLock();
} }
void Unit::deleteQueuedCommand(Command *command) { void Unit::deleteQueuedCommand(Command *command) {

View File

@ -292,7 +292,8 @@ void World::updateAllFactionUnits() {
unitsInFactionsSorted[faction->getIndex()].push_back(CommandGroupSorter(unit)); unitsInFactionsSorted[faction->getIndex()].push_back(CommandGroupSorter(unit));
} }
std::sort(unitsInFactionsSorted[faction->getIndex()].begin(),unitsInFactionsSorted[faction->getIndex()].end()); std::vector<CommandGroupSorter> &unitListToSort = unitsInFactionsSorted[faction->getIndex()];
std::sort(unitListToSort.begin(),unitListToSort.end());
} }
// Signal the faction threads to do any pre-processing // Signal the faction threads to do any pre-processing
@ -301,7 +302,8 @@ void World::updateAllFactionUnits() {
if(faction == NULL) { if(faction == NULL) {
throw runtime_error("faction == NULL"); throw runtime_error("faction == NULL");
} }
faction->signalWorkerThread(frameCount,&unitsInFactionsSorted[faction->getIndex()]); std::vector<CommandGroupSorter> &unitListSorted = unitsInFactionsSorted[faction->getIndex()];
faction->signalWorkerThread(frameCount,&unitListSorted);
} }
bool workThreadsFinished = false; bool workThreadsFinished = false;
@ -338,9 +340,11 @@ void World::updateAllFactionUnits() {
throw runtime_error("faction == NULL"); throw runtime_error("faction == NULL");
} }
int unitCount = unitsInFactionsSorted[faction->getIndex()].size(); std::vector<CommandGroupSorter> &unitListSorted = unitsInFactionsSorted[faction->getIndex()];
int unitCount = unitListSorted.size();
for(int j = 0; j < unitCount; ++j) { for(int j = 0; j < unitCount; ++j) {
Unit *unit = unitsInFactionsSorted[faction->getIndex()][j].unit; Unit *unit = unitListSorted[j].unit;
if(unit == NULL) { if(unit == NULL) {
throw runtime_error("unit == NULL"); throw runtime_error("unit == NULL");
} }