mirror of
https://gitlab.com/Mr_Goldberg/goldberg_emulator.git
synced 2024-11-09 22:28:38 +01:00
Fix possible thread issue.
This commit is contained in:
parent
29e713b94c
commit
e6031c7597
1 changed files with 13 additions and 6 deletions
|
@ -70,6 +70,8 @@ public ISteamNetworking
|
||||||
|
|
||||||
std::recursive_mutex messages_mutex;
|
std::recursive_mutex messages_mutex;
|
||||||
std::vector<Common_Message> messages;
|
std::vector<Common_Message> messages;
|
||||||
|
|
||||||
|
std::recursive_mutex connections_edit_mutex;
|
||||||
std::vector<struct Steam_Networking_Connection> connections;
|
std::vector<struct Steam_Networking_Connection> connections;
|
||||||
|
|
||||||
std::vector<struct steam_listen_socket> listen_sockets;
|
std::vector<struct steam_listen_socket> listen_sockets;
|
||||||
|
@ -79,11 +81,13 @@ public ISteamNetworking
|
||||||
|
|
||||||
bool connection_exists(CSteamID id)
|
bool connection_exists(CSteamID id)
|
||||||
{
|
{
|
||||||
|
std::lock_guard<std::recursive_mutex> lock(connections_edit_mutex);
|
||||||
return std::find_if(connections.begin(), connections.end(), [&id](struct Steam_Networking_Connection const& conn) { return conn.remote == id;}) != connections.end();
|
return std::find_if(connections.begin(), connections.end(), [&id](struct Steam_Networking_Connection const& conn) { return conn.remote == id;}) != connections.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Steam_Networking_Connection *get_or_create_connection(CSteamID id)
|
struct Steam_Networking_Connection *get_or_create_connection(CSteamID id)
|
||||||
{
|
{
|
||||||
|
std::lock_guard<std::recursive_mutex> lock(connections_edit_mutex);
|
||||||
auto conn = std::find_if(connections.begin(), connections.end(), [&id](struct Steam_Networking_Connection const& conn) { return conn.remote == id;});
|
auto conn = std::find_if(connections.begin(), connections.end(), [&id](struct Steam_Networking_Connection const& conn) { return conn.remote == id;});
|
||||||
|
|
||||||
if (connections.end() == conn) {
|
if (connections.end() == conn) {
|
||||||
|
@ -98,6 +102,8 @@ struct Steam_Networking_Connection *get_or_create_connection(CSteamID id)
|
||||||
|
|
||||||
void remove_connection(CSteamID id)
|
void remove_connection(CSteamID id)
|
||||||
{
|
{
|
||||||
|
{
|
||||||
|
std::lock_guard<std::recursive_mutex> lock(connections_edit_mutex);
|
||||||
auto conn = std::begin(connections);
|
auto conn = std::begin(connections);
|
||||||
while (conn != std::end(connections)) {
|
while (conn != std::end(connections)) {
|
||||||
if (conn->remote == id) {
|
if (conn->remote == id) {
|
||||||
|
@ -107,6 +113,7 @@ void remove_connection(CSteamID id)
|
||||||
++conn;
|
++conn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//pretty sure steam also clears the entire queue of messages for that connection
|
//pretty sure steam also clears the entire queue of messages for that connection
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue