avoid locking the global_mutex every time when getting the global steamclient instance, double check for null and lock on the first time the pointer is initialized, should speed things up

This commit is contained in:
a 2023-11-10 13:39:40 +02:00
parent 3999818a6b
commit caa4024de3

View File

@ -132,9 +132,12 @@ ISteamClient *g_pSteamClientGameServer;
static Steam_Client *steamclient_instance; static Steam_Client *steamclient_instance;
Steam_Client *get_steam_client() Steam_Client *get_steam_client()
{ {
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (!steamclient_instance) { if (!steamclient_instance) {
steamclient_instance = new Steam_Client(); std::lock_guard<std::recursive_mutex> lock(global_mutex);
// if we win the thread arbitration for the first time, this will still be null
if (!steamclient_instance) {
steamclient_instance = new Steam_Client();
}
} }
return steamclient_instance; return steamclient_instance;