Skip to content

Instantly share code, notes, and snippets.

@nielsmh
Created April 10, 2021 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nielsmh/1419be0703c75c7e321a00ce6c94debc to your computer and use it in GitHub Desktop.
Save nielsmh/1419be0703c75c7e321a00ce6c94debc to your computer and use it in GitHub Desktop.
--- a/src/network/network_udp.cpp
+++ b/src/network/network_udp.cpp
@@ -646,7 +646,9 @@ void NetworkUDPClose()
/** Receive the UDP packets. */
void NetworkBackgroundUDPLoop()
{
- std::lock_guard<std::mutex> lock(_network_udp_mutex);
+ /* Try to take the lock, but do nothing if the mutex is already held. Avoid blocking the main network loop. */
+ if (!_network_udp_mutex.try_lock()) return;
+ std::lock_guard<std::mutex> lock(_network_udp_mutex, std::adopt_lock);
if (_network_udp_server) {
_udp_server_socket->ReceivePackets();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment