diff options
author | SmallJoker <SmallJoker@users.noreply.github.com> | 2019-08-17 13:27:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-17 13:27:28 +0200 |
commit | d73e458db6ab7748fcc7fd485f246971725ea48a (patch) | |
tree | 9fb9193c2da45eac245794af8205bcd63d621080 | |
parent | 13b22e2afb57eb2da0513f2caca4e88549f55d0a (diff) | |
download | minetest-d73e458db6ab7748fcc7fd485f246971725ea48a.tar.gz minetest-d73e458db6ab7748fcc7fd485f246971725ea48a.tar.bz2 minetest-d73e458db6ab7748fcc7fd485f246971725ea48a.zip |
ClientInterface: Use recursive mutex to prevent freeze in on_newplayer() (#8808)
-rw-r--r-- | src/clientiface.cpp | 28 | ||||
-rw-r--r-- | src/clientiface.h | 2 |
2 files changed, 15 insertions, 15 deletions
diff --git a/src/clientiface.cpp b/src/clientiface.cpp index a55e0f7b5..dceaa64f2 100644 --- a/src/clientiface.cpp +++ b/src/clientiface.cpp @@ -636,7 +636,7 @@ ClientInterface::~ClientInterface() Delete clients */ { - MutexAutoLock clientslock(m_clients_mutex); + RecursiveMutexAutoLock clientslock(m_clients_mutex); for (auto &client_it : m_clients) { // Delete client @@ -648,7 +648,7 @@ ClientInterface::~ClientInterface() std::vector<session_t> ClientInterface::getClientIDs(ClientState min_state) { std::vector<session_t> reply; - MutexAutoLock clientslock(m_clients_mutex); + RecursiveMutexAutoLock clientslock(m_clients_mutex); for (const auto &m_client : m_clients) { if (m_client.second->getState() >= min_state) @@ -660,7 +660,7 @@ std::vector<session_t> ClientInterface::getClientIDs(ClientState min_state) void ClientInterface::markBlockposAsNotSent(const v3s16 &pos) { - MutexAutoLock clientslock(m_clients_mutex); + RecursiveMutexAutoLock clientslock(m_clients_mutex); for (const auto &client : m_clients) { if (client.second->getState() >= CS_Active) client.second->SetBlockNotSent(pos); @@ -705,7 +705,7 @@ void ClientInterface::UpdatePlayerList() infostream << "* " << player->getName() << "\t"; { - MutexAutoLock clientslock(m_clients_mutex); + RecursiveMutexAutoLock clientslock(m_clients_mutex); RemoteClient* client = lockedGetClientNoEx(i); if (client) client->PrintInfo(infostream); @@ -724,7 +724,7 @@ void ClientInterface::send(session_t peer_id, u8 channelnum, void ClientInterface::sendToAll(NetworkPacket *pkt) { - MutexAutoLock clientslock(m_clients_mutex); + RecursiveMutexAutoLock clientslock(m_clients_mutex); for (auto &client_it : m_clients) { RemoteClient *client = client_it.second; @@ -739,7 +739,7 @@ void ClientInterface::sendToAll(NetworkPacket *pkt) void ClientInterface::sendToAllCompat(NetworkPacket *pkt, NetworkPacket *legacypkt, u16 min_proto_ver) { - MutexAutoLock clientslock(m_clients_mutex); + RecursiveMutexAutoLock clientslock(m_clients_mutex); for (auto &client_it : m_clients) { RemoteClient *client = client_it.second; NetworkPacket *pkt_to_send = nullptr; @@ -763,7 +763,7 @@ void ClientInterface::sendToAllCompat(NetworkPacket *pkt, NetworkPacket *legacyp RemoteClient* ClientInterface::getClientNoEx(session_t peer_id, ClientState state_min) { - MutexAutoLock clientslock(m_clients_mutex); + RecursiveMutexAutoLock clientslock(m_clients_mutex); RemoteClientMap::const_iterator n = m_clients.find(peer_id); // The client may not exist; clients are immediately removed if their // access is denied, and this event occurs later then. @@ -792,7 +792,7 @@ RemoteClient* ClientInterface::lockedGetClientNoEx(session_t peer_id, ClientStat ClientState ClientInterface::getClientState(session_t peer_id) { - MutexAutoLock clientslock(m_clients_mutex); + RecursiveMutexAutoLock clientslock(m_clients_mutex); RemoteClientMap::const_iterator n = m_clients.find(peer_id); // The client may not exist; clients are immediately removed if their // access is denied, and this event occurs later then. @@ -804,7 +804,7 @@ ClientState ClientInterface::getClientState(session_t peer_id) void ClientInterface::setPlayerName(session_t peer_id, const std::string &name) { - MutexAutoLock clientslock(m_clients_mutex); + RecursiveMutexAutoLock clientslock(m_clients_mutex); RemoteClientMap::iterator n = m_clients.find(peer_id); // The client may not exist; clients are immediately removed if their // access is denied, and this event occurs later then. @@ -814,7 +814,7 @@ void ClientInterface::setPlayerName(session_t peer_id, const std::string &name) void ClientInterface::DeleteClient(session_t peer_id) { - MutexAutoLock conlock(m_clients_mutex); + RecursiveMutexAutoLock conlock(m_clients_mutex); // Error check RemoteClientMap::iterator n = m_clients.find(peer_id); @@ -844,7 +844,7 @@ void ClientInterface::DeleteClient(session_t peer_id) void ClientInterface::CreateClient(session_t peer_id) { - MutexAutoLock conlock(m_clients_mutex); + RecursiveMutexAutoLock conlock(m_clients_mutex); // Error check RemoteClientMap::iterator n = m_clients.find(peer_id); @@ -860,7 +860,7 @@ void ClientInterface::CreateClient(session_t peer_id) void ClientInterface::event(session_t peer_id, ClientStateEvent event) { { - MutexAutoLock clientlock(m_clients_mutex); + RecursiveMutexAutoLock clientlock(m_clients_mutex); // Error check RemoteClientMap::iterator n = m_clients.find(peer_id); @@ -881,7 +881,7 @@ void ClientInterface::event(session_t peer_id, ClientStateEvent event) u16 ClientInterface::getProtocolVersion(session_t peer_id) { - MutexAutoLock conlock(m_clients_mutex); + RecursiveMutexAutoLock conlock(m_clients_mutex); // Error check RemoteClientMap::iterator n = m_clients.find(peer_id); @@ -896,7 +896,7 @@ u16 ClientInterface::getProtocolVersion(session_t peer_id) void ClientInterface::setClientVersion(session_t peer_id, u8 major, u8 minor, u8 patch, const std::string &full) { - MutexAutoLock conlock(m_clients_mutex); + RecursiveMutexAutoLock conlock(m_clients_mutex); // Error check RemoteClientMap::iterator n = m_clients.find(peer_id); diff --git a/src/clientiface.h b/src/clientiface.h index 5335fa644..2b0ccfbb1 100644 --- a/src/clientiface.h +++ b/src/clientiface.h @@ -501,7 +501,7 @@ private: // Connection std::shared_ptr<con::Connection> m_con; - std::mutex m_clients_mutex; + std::recursive_mutex m_clients_mutex; // Connected clients (behind the con mutex) RemoteClientMap m_clients; std::vector<std::string> m_clients_names; //for announcing masterserver |