4444#include < string>
4545#include < utility>
4646#include < vector>
47+
4748// Global lock to prevent reading JSON manifest files at the same time.
48- static std::mutex g_loader_json_mutex;
49+ std::mutex &GetLoaderJsonMutex () {
50+ static std::mutex loader_json_mutex;
51+ return loader_json_mutex;
52+ }
4953
5054// Global lock to prevent simultaneous instance creation/destruction
51- static std::mutex g_instance_create_destroy_mutex;
55+ std::mutex &GetInstanceCreateDestroyMutex () {
56+ static std::mutex instance_create_destroy_mutex;
57+ return instance_create_destroy_mutex;
58+ }
5259
5360// Terminal functions needed by xrCreateInstance.
5461XRAPI_ATTR XrResult XRAPI_CALL LoaderXrTermGetInstanceProcAddr (XrInstance, const char *, PFN_xrVoidFunction *);
@@ -84,7 +91,7 @@ LOADER_EXPORT XRAPI_ATTR XrResult XRAPI_CALL xrEnumerateApiLayerProperties(uint3
8491 LoaderLogger::LogVerboseMessage (" xrEnumerateApiLayerProperties" , " Entering loader trampoline" );
8592
8693 // Make sure only one thread is attempting to read the JSON files at a time.
87- std::unique_lock<std::mutex> json_lock (g_loader_json_mutex );
94+ std::unique_lock<std::mutex> json_lock (GetLoaderJsonMutex () );
8895
8996 XrResult result = ApiLayerInterface::GetApiLayerProperties (" xrEnumerateApiLayerProperties" , propertyCapacityInput,
9097 propertyCountOutput, properties);
@@ -118,7 +125,7 @@ xrEnumerateInstanceExtensionProperties(const char *layerName, uint32_t propertyC
118125
119126 {
120127 // Make sure only one thread is attempting to read the JSON files at a time.
121- std::unique_lock<std::mutex> json_lock (g_loader_json_mutex );
128+ std::unique_lock<std::mutex> json_lock (GetLoaderJsonMutex () );
122129
123130 // Get the layer extension properties
124131 result = ApiLayerInterface::GetInstanceExtensionProperties (" xrEnumerateInstanceExtensionProperties" , layerName,
@@ -235,7 +242,7 @@ LOADER_EXPORT XRAPI_ATTR XrResult XRAPI_CALL xrCreateInstance(const XrInstanceCr
235242 return XR_ERROR_VALIDATION_FAILURE;
236243 }
237244
238- std::unique_lock<std::mutex> instance_lock (g_instance_create_destroy_mutex );
245+ std::unique_lock<std::mutex> instance_lock (GetInstanceCreateDestroyMutex () );
239246
240247 // Check if there is already an XrInstance that is alive. If so, another instance cannot be created.
241248 // The loader does not support multiple simultaneous instances because the loader is intended to be
@@ -252,7 +259,7 @@ LOADER_EXPORT XRAPI_ATTR XrResult XRAPI_CALL xrCreateInstance(const XrInstanceCr
252259
253260 // Make sure only one thread is attempting to read the JSON files and use the instance.
254261 {
255- std::unique_lock<std::mutex> json_lock (g_loader_json_mutex );
262+ std::unique_lock<std::mutex> json_lock (GetLoaderJsonMutex () );
256263 // Load the available runtime
257264 result = RuntimeInterface::LoadRuntime (" xrCreateInstance" );
258265 if (XR_FAILED (result)) {
@@ -329,7 +336,7 @@ LOADER_EXPORT XRAPI_ATTR XrResult XRAPI_CALL xrDestroyInstance(XrInstance instan
329336 return XR_ERROR_HANDLE_INVALID;
330337 }
331338
332- std::unique_lock<std::mutex> loader_instance_lock (g_instance_create_destroy_mutex );
339+ std::unique_lock<std::mutex> loader_instance_lock (GetInstanceCreateDestroyMutex () );
333340
334341 LoaderInstance *loader_instance;
335342 XrResult result = ActiveLoaderInstance::Get (&loader_instance, " xrDestroyInstance" );
@@ -657,7 +664,7 @@ XRAPI_ATTR XrResult XRAPI_CALL LoaderXrTermCreateDebugUtilsMessengerEXT(XrInstan
657664 *messenger = reinterpret_cast <XrDebugUtilsMessengerEXT>(temp_mess_ptr);
658665 }
659666 if (XR_SUCCEEDED (result)) {
660- LoaderLogger::GetInstance ().AddLogRecorderForXrInstance (instance, MakeDebugUtilsLoaderLogRecorder (createInfo, *messenger));
667+ LoaderLogger::GetInstance ().AddLogRecorder ( MakeDebugUtilsLoaderLogRecorder (createInfo, *messenger));
661668 RuntimeInterface::GetRuntime ().TrackDebugMessenger (instance, *messenger);
662669 }
663670 LoaderLogger::LogVerboseMessage (" xrCreateDebugUtilsMessengerEXT" , " Completed loader terminator" );
0 commit comments