[ServerList] Use recursive mutex
This commit is contained in:
parent
55b0fbcedb
commit
2e01137ff8
@ -120,11 +120,7 @@ namespace Components
|
|||||||
Logger::Error("Failed to parse bans (bans.json): %s", error.data());
|
Logger::Error("Failed to parse bans (bans.json): %s", error.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!list)
|
if (!list) return;
|
||||||
{
|
|
||||||
Bans::AccessMutex.unlock();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (banData.is_object())
|
if (banData.is_object())
|
||||||
{
|
{
|
||||||
|
@ -80,7 +80,7 @@ namespace Components
|
|||||||
|
|
||||||
if (ServerList::IsOfflineList())
|
if (ServerList::IsOfflineList())
|
||||||
{
|
{
|
||||||
ServerList::InsertRequest(address, true);
|
ServerList::InsertRequest(address);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -778,7 +778,7 @@ namespace Components
|
|||||||
|
|
||||||
if (!Dedicated::IsEnabled() && entry->isDedi && ServerList::IsOnlineList() && entry->protocol == PROTOCOL)
|
if (!Dedicated::IsEnabled() && entry->isDedi && ServerList::IsOnlineList() && entry->protocol == PROTOCOL)
|
||||||
{
|
{
|
||||||
ServerList::InsertRequest(entry->address, true);
|
ServerList::InsertRequest(entry->address);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < list.address_size(); ++i)
|
for (int i = 0; i < list.address_size(); ++i)
|
||||||
|
@ -179,14 +179,14 @@ namespace Components
|
|||||||
{
|
{
|
||||||
list->clear();
|
list->clear();
|
||||||
|
|
||||||
std::lock_guard<std::mutex> _(ServerList::RefreshContainer.mutex);
|
std::lock_guard<std::recursive_mutex> _(ServerList::RefreshContainer.mutex);
|
||||||
|
|
||||||
ServerList::RefreshContainer.sendCount = 0;
|
ServerList::RefreshContainer.sendCount = 0;
|
||||||
ServerList::RefreshContainer.sentCount = 0;
|
ServerList::RefreshContainer.sentCount = 0;
|
||||||
|
|
||||||
for (auto server : tempList)
|
for (auto server : tempList)
|
||||||
{
|
{
|
||||||
ServerList::InsertRequest(server.addr, false);
|
ServerList::InsertRequest(server.addr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -387,14 +387,14 @@ namespace Components
|
|||||||
for (unsigned int i = 0; i < servers.size(); ++i)
|
for (unsigned int i = 0; i < servers.size(); ++i)
|
||||||
{
|
{
|
||||||
if(!servers[i].is_string()) continue;
|
if(!servers[i].is_string()) continue;
|
||||||
ServerList::InsertRequest(servers[i].string_value(), true);
|
ServerList::InsertRequest(servers[i].string_value());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerList::InsertRequest(Network::Address address, bool acquireMutex)
|
void ServerList::InsertRequest(Network::Address address)
|
||||||
{
|
{
|
||||||
if (acquireMutex) ServerList::RefreshContainer.mutex.lock();
|
std::lock_guard<std::recursive_mutex> _(ServerList::RefreshContainer.mutex);
|
||||||
|
|
||||||
ServerList::Container::ServerContainer container;
|
ServerList::Container::ServerContainer container;
|
||||||
container.sent = false;
|
container.sent = false;
|
||||||
@ -430,13 +430,11 @@ namespace Components
|
|||||||
|
|
||||||
++ServerList::RefreshContainer.sendCount;
|
++ServerList::RefreshContainer.sendCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (acquireMutex) ServerList::RefreshContainer.mutex.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerList::Insert(Network::Address address, Utils::InfoString info)
|
void ServerList::Insert(Network::Address address, Utils::InfoString info)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> _(ServerList::RefreshContainer.mutex);
|
std::lock_guard<std::recursive_mutex> _(ServerList::RefreshContainer.mutex);
|
||||||
|
|
||||||
for (auto i = ServerList::RefreshContainer.servers.begin(); i != ServerList::RefreshContainer.servers.end();)
|
for (auto i = ServerList::RefreshContainer.servers.begin(); i != ServerList::RefreshContainer.servers.end();)
|
||||||
{
|
{
|
||||||
@ -731,7 +729,7 @@ namespace Components
|
|||||||
|
|
||||||
ServerList::RefreshContainer.awatingList = false;
|
ServerList::RefreshContainer.awatingList = false;
|
||||||
|
|
||||||
std::lock_guard<std::mutex> _(ServerList::RefreshContainer.mutex);
|
std::lock_guard<std::recursive_mutex> _(ServerList::RefreshContainer.mutex);
|
||||||
|
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
int count = ServerList::RefreshContainer.servers.size();
|
int count = ServerList::RefreshContainer.servers.size();
|
||||||
@ -751,7 +749,7 @@ namespace Components
|
|||||||
serverAddr.setPort(ntohs(entry[i].port));
|
serverAddr.setPort(ntohs(entry[i].port));
|
||||||
serverAddr.setType(Game::NA_IP);
|
serverAddr.setType(Game::NA_IP);
|
||||||
|
|
||||||
ServerList::InsertRequest(serverAddr, false);
|
ServerList::InsertRequest(serverAddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::Print("Parsed %d servers from master\n", ServerList::RefreshContainer.servers.size() - count);
|
Logger::Print("Parsed %d servers from master\n", ServerList::RefreshContainer.servers.size() - count);
|
||||||
|
@ -39,7 +39,7 @@ namespace Components
|
|||||||
static void Refresh(UIScript::Token);
|
static void Refresh(UIScript::Token);
|
||||||
static void RefreshVisibleList(UIScript::Token);
|
static void RefreshVisibleList(UIScript::Token);
|
||||||
static void UpdateVisibleList(UIScript::Token);
|
static void UpdateVisibleList(UIScript::Token);
|
||||||
static void InsertRequest(Network::Address address, bool acquireMutex = true);
|
static void InsertRequest(Network::Address address);
|
||||||
static void Insert(Network::Address address, Utils::InfoString info);
|
static void Insert(Network::Address address, Utils::InfoString info);
|
||||||
|
|
||||||
static ServerInfo* GetCurrentServer();
|
static ServerInfo* GetCurrentServer();
|
||||||
@ -109,7 +109,7 @@ namespace Components
|
|||||||
|
|
||||||
Network::Address host;
|
Network::Address host;
|
||||||
std::vector<ServerContainer> servers;
|
std::vector<ServerContainer> servers;
|
||||||
std::mutex mutex;
|
std::recursive_mutex mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
static unsigned int GetServerCount();
|
static unsigned int GetServerCount();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user