loader: Preload ICD use its own mutex
authorCharles Giessen <charles@lunarg.com>
Tue, 12 May 2020 20:25:47 +0000 (14:25 -0600)
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>
Fri, 15 May 2020 19:18:31 +0000 (13:18 -0600)
Previously, if a layer called a pre-instance function
while being initialized (inside vkCreateInstance) a deadlock
would occur because the preload icd call used the same mutex.

Change-Id: I085ecfbcab26d746d77ca8466b4f63a13f6bea10

loader/loader.c
loader/loader.h

index 15e4faa0da1a6abe3bb06baad17435c6841b951e..02de3c264bc830fa346317ba13b5cf81f7be5a18 100644 (file)
@@ -121,6 +121,7 @@ enum loader_data_files_type {
 // additionally CreateDevice and DestroyDevice needs to be locked
 loader_platform_thread_mutex loader_lock;
 loader_platform_thread_mutex loader_json_lock;
+loader_platform_thread_mutex loader_preload_icd_lock;
 
 // A list of ICDs that gets initialized when the loader does its global initialization. This list should never be used by anything
 // other than EnumerateInstanceExtensionProperties(), vkDestroyInstance, and loader_release(). This list does not change
@@ -2433,7 +2434,7 @@ void loader_initialize(void) {
     // initialize mutexes
     loader_platform_thread_create_mutex(&loader_lock);
     loader_platform_thread_create_mutex(&loader_json_lock);
-
+    loader_platform_thread_create_mutex(&loader_preload_icd_lock);
     // initialize logging
     loader_debug_init();
 
@@ -2463,15 +2464,16 @@ void loader_release() {
     // release mutexes
     loader_platform_thread_delete_mutex(&loader_lock);
     loader_platform_thread_delete_mutex(&loader_json_lock);
+    loader_platform_thread_delete_mutex(&loader_preload_icd_lock);
 }
 
 // Preload the ICD libraries that are likely to be needed so we don't repeatedly load/unload them later
 void loader_preload_icds(void) {
-    loader_platform_thread_lock_mutex(&loader_lock);
+    loader_platform_thread_lock_mutex(&loader_preload_icd_lock);
 
     // Already preloaded, skip loading again.
     if (scanned_icds.scanned_list != NULL) {
-        loader_platform_thread_unlock_mutex(&loader_lock);
+        loader_platform_thread_unlock_mutex(&loader_preload_icd_lock);
         return;
     }
 
@@ -2480,14 +2482,14 @@ void loader_preload_icds(void) {
     if (result != VK_SUCCESS) {
         loader_scanned_icd_clear(NULL, &scanned_icds);
     }
-    loader_platform_thread_unlock_mutex(&loader_lock);
+    loader_platform_thread_unlock_mutex(&loader_preload_icd_lock);
 }
 
 // Release the ICD libraries that were preloaded
 void loader_unload_preloaded_icds(void) {
-    loader_platform_thread_lock_mutex(&loader_lock);
+    loader_platform_thread_lock_mutex(&loader_preload_icd_lock);
     loader_scanned_icd_clear(NULL, &scanned_icds);
-    loader_platform_thread_unlock_mutex(&loader_lock);
+    loader_platform_thread_unlock_mutex(&loader_preload_icd_lock);
 }
 
 // Get next file or dirname given a string list or registry key path
index 0182c74478ea42a616387ab34726ad8ac8d510b9..463b74e19d7cbb8d259c695ef11352153367bd3f 100644 (file)
@@ -422,6 +422,7 @@ extern struct loader_struct loader;
 extern THREAD_LOCAL_DECL struct loader_instance *tls_instance;
 extern loader_platform_thread_mutex loader_lock;
 extern loader_platform_thread_mutex loader_json_lock;
+extern loader_platform_thread_mutex loader_preload_icd_lock;
 
 struct loader_msg_callback_map_entry {
     VkDebugReportCallbackEXT icd_obj;