From caa4024de378f8dcc5eb7361f8ca2fd2d60e773b Mon Sep 17 00:00:00 2001 From: a Date: Fri, 10 Nov 2023 13:39:40 +0200 Subject: [PATCH] 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 --- dll/dll.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dll/dll.cpp b/dll/dll.cpp index 4fef7159..18e54c9d 100644 --- a/dll/dll.cpp +++ b/dll/dll.cpp @@ -132,9 +132,12 @@ ISteamClient *g_pSteamClientGameServer; static Steam_Client *steamclient_instance; Steam_Client *get_steam_client() { - std::lock_guard lock(global_mutex); if (!steamclient_instance) { - steamclient_instance = new Steam_Client(); + std::lock_guard 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;