layers: release mutex in DrawState
authorMike Stroyan <mike@LunarG.com>
Tue, 18 Aug 2015 21:56:18 +0000 (15:56 -0600)
committerMike Stroyan <mike@LunarG.com>
Wed, 23 Sep 2015 18:33:57 +0000 (12:33 -0600)
Release mutex when last instance is destroyed.

layers/draw_state.cpp

index a0780fdacc2282f9ea3d17bbf9ec6880f7f90016..10fa70cd91e66220fd9099a3252a9632bd38a93f 100644 (file)
@@ -1251,11 +1251,7 @@ static void init_draw_state(layer_data *my_data)
 
     if (!globalLockInitialized)
     {
-        // TODO/TBD: Need to delete this mutex sometime.  How???  One
-        // suggestion is to call this during vkCreateInstance(), and then we
-        // can clean it up during vkDestroyInstance().  However, that requires
-        // that the layer have per-instance locks.  We need to come back and
-        // address this soon.
+        // This mutex may be deleted by vkDestroyInstance of last instance.
         loader_platform_thread_create_mutex(&globalLock);
         globalLockInitialized = 1;
     }
@@ -1296,6 +1292,11 @@ VK_LAYER_EXPORT void VKAPI vkDestroyInstance(VkInstance instance)
     layer_data_map.erase(pTable);
 
     draw_state_instance_table_map.erase(key);
+    if (draw_state_instance_table_map.empty()) {
+        // Release mutex when destroying last instance.
+        loader_platform_thread_delete_mutex(&globalLock);
+        globalLockInitialized = 0;
+    }
 }
 
 static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)