tpl_vk_wsi_thread: Enhanced thread safety for destroy swapchain. 42/188942/1
authorJoonbum Ko <joonbum.ko@samsung.com>
Wed, 12 Sep 2018 04:13:31 +0000 (13:13 +0900)
committerJoonbum Ko <joonbum.ko@samsung.com>
Wed, 12 Sep 2018 04:13:43 +0000 (13:13 +0900)
 - If wayland events handled in the event thread during destroy_swapchain,
  unexpected problem can occur related wayland-tbm.

Change-Id: I0b80e2784f8a51590ad238ffb63dcc783db2f969
Signed-off-by: Joonbum Ko <joonbum.ko@samsung.com>
src/tpl_wl_vk_thread.c

index 2242975..73378d1 100644 (file)
@@ -685,39 +685,45 @@ static tpl_result_t
 __tpl_wl_vk_wsi_surface_destroy_swapchain(tpl_surface_t *surface)
 {
        tpl_wayland_vk_wsi_surface_t *wayland_vk_wsi_surface = NULL;
+       tpl_wayland_vk_wsi_display_t *wayland_vk_wsi_display = NULL;
        tpl_result_t res = TPL_ERROR_NONE;
        unsigned int ref;
 
        TPL_ASSERT(surface);
        TPL_ASSERT(surface->backend.data);
        TPL_ASSERT(surface->display);
+       TPL_ASSERT(surface->display->backend.data);
 
        wayland_vk_wsi_surface = (tpl_wayland_vk_wsi_surface_t *) surface->backend.data;
-       TPL_ASSERT(wayland_vk_wsi_surface);
+       wayland_vk_wsi_display = (tpl_wayland_vk_wsi_display_t *) surface->display->backend.data;
 
-       ref = __tpl_util_atomic_dec(&wayland_vk_wsi_surface->swapchain_reference);
-       if (ref > 0) {
-               TPL_LOG_T("WL_VK",
-                                 "This swapchain is still valid. | twe_surface(%p)",
-                                 wayland_vk_wsi_surface->twe_surface);
-               return TPL_ERROR_NONE;
-       }
+       if (twe_display_lock(wayland_vk_wsi_display->twe_display) == TPL_ERROR_NONE) {
+               ref = __tpl_util_atomic_dec(&wayland_vk_wsi_surface->swapchain_reference);
+               if (ref > 0) {
+                       TPL_LOG_T("WL_VK",
+                                         "This swapchain is still valid. | twe_surface(%p)",
+                                         wayland_vk_wsi_surface->twe_surface);
+                       return TPL_ERROR_NONE;
+               }
 
 
-       if (wayland_vk_wsi_surface->reset) {
-               TPL_LOG_T("WL_VK",
-                                 "Since reset is in the TRUE state, it will not be destroyed.");
-               return TPL_ERROR_NONE;
-       }
+               if (wayland_vk_wsi_surface->reset) {
+                       TPL_LOG_T("WL_VK",
+                                         "Since reset is in the TRUE state, it will not be destroyed.");
+                       return TPL_ERROR_NONE;
+               }
 
-       res = twe_surface_destroy_swapchain(wayland_vk_wsi_surface->twe_surface);
-       if (res != TPL_ERROR_NONE) {
-               TPL_ERR("Failed to destroy swapchain. twe_surface(%p)",
-                               wayland_vk_wsi_surface->twe_surface);
-               return res;
-       }
+               res = twe_surface_destroy_swapchain(wayland_vk_wsi_surface->twe_surface);
+               if (res != TPL_ERROR_NONE) {
+                       TPL_ERR("Failed to destroy swapchain. twe_surface(%p)",
+                                       wayland_vk_wsi_surface->twe_surface);
+                       return res;
+               }
 
-       wayland_vk_wsi_surface->tbm_queue = NULL;
+               wayland_vk_wsi_surface->tbm_queue = NULL;
+
+               twe_display_unlock(wayland_vk_wsi_display->twe_display);
+       }
 
        return TPL_ERROR_NONE;
 }