mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-01 23:35:41 +00:00
fix deadlock in DeleteCar
This commit is contained in:
parent
d4d773b769
commit
a584e25bf3
@ -31,7 +31,6 @@ public:
|
|||||||
void SetName(const std::string& Name) { mName = Name; }
|
void SetName(const std::string& Name) { mName = Name; }
|
||||||
void SetRoles(const std::string& Role) { mRole = Role; }
|
void SetRoles(const std::string& Role) { mRole = Role; }
|
||||||
void AddIdentifier(const std::string& ID) { mIdentifiers.insert(ID); };
|
void AddIdentifier(const std::string& ID) { mIdentifiers.insert(ID); };
|
||||||
void EraseVehicle(TVehicleData& VehicleData);
|
|
||||||
std::string GetCarData(int Ident);
|
std::string GetCarData(int Ident);
|
||||||
void SetUDPAddr(sockaddr_in Addr) { mUDPAddress = Addr; }
|
void SetUDPAddr(sockaddr_in Addr) { mUDPAddress = Addr; }
|
||||||
void SetDownSock(SOCKET CSock) { mSocket[1] = CSock; }
|
void SetDownSock(SOCKET CSock) { mSocket[1] = CSock; }
|
||||||
|
@ -6,24 +6,14 @@
|
|||||||
// FIXME: add debug prints
|
// FIXME: add debug prints
|
||||||
|
|
||||||
void TClient::DeleteCar(int Ident) {
|
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);
|
std::unique_lock lock(mVehicleDataMutex);
|
||||||
auto iter = std::find_if(mVehicleData.begin(), mVehicleData.end(), [&](auto& elem) {
|
auto iter = std::find_if(mVehicleData.begin(), mVehicleData.end(), [&](auto& elem) {
|
||||||
return VehicleData.ID() == elem.ID();
|
return Ident == elem.ID();
|
||||||
});
|
});
|
||||||
if (iter != mVehicleData.end()) {
|
if (iter != mVehicleData.end()) {
|
||||||
mVehicleData.erase(iter);
|
mVehicleData.erase(iter);
|
||||||
} else {
|
} else {
|
||||||
debug("tried to erase a vehicle that doesn't exist!");
|
debug("tried to erase a vehicle that doesn't exist (not an error)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user