fix deadlock in DeleteCar

This commit is contained in:
Lion Kortlepel
2021-03-31 14:44:50 +02:00
parent d4d773b769
commit a584e25bf3
2 changed files with 2 additions and 13 deletions

View File

@@ -6,24 +6,14 @@
// FIXME: add debug prints
void TClient::DeleteCar(int Ident) {
std::unique_lock lock(mVehicleDataMutex);
for (auto& v : mVehicleData) {
if (v.ID() == Ident) {
EraseVehicle(v);
break;
}
}
}
void TClient::EraseVehicle(TVehicleData& VehicleData) {
std::unique_lock lock(mVehicleDataMutex);
auto iter = std::find_if(mVehicleData.begin(), mVehicleData.end(), [&](auto& elem) {
return VehicleData.ID() == elem.ID();
return Ident == elem.ID();
});
if (iter != mVehicleData.end()) {
mVehicleData.erase(iter);
} else {
debug("tried to erase a vehicle that doesn't exist!");
debug("tried to erase a vehicle that doesn't exist (not an error)");
}
}