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

@ -31,7 +31,6 @@ public:
void SetName(const std::string& Name) { mName = Name; }
void SetRoles(const std::string& Role) { mRole = Role; }
void AddIdentifier(const std::string& ID) { mIdentifiers.insert(ID); };
void EraseVehicle(TVehicleData& VehicleData);
std::string GetCarData(int Ident);
void SetUDPAddr(sockaddr_in Addr) { mUDPAddress = Addr; }
void SetDownSock(SOCKET CSock) { mSocket[1] = CSock; }

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)");
}
}