tpl_wl_egl_thread: Modified to ensure thread safety between enqueue and destroy. 39/149839/4
authorjoonbum.ko <joonbum.ko@samsung.com>
Wed, 13 Sep 2017 07:59:59 +0000 (16:59 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Fri, 15 Sep 2017 11:46:25 +0000 (11:46 +0000)
Change-Id: I36af6adb3956112093ddcd2304f31b5ab26705f3
Signed-off-by: joonbum.ko <joonbum.ko@samsung.com>
src/tpl_wl_egl_thread.c

index 43c093b..0a590ca 100644 (file)
@@ -27,6 +27,7 @@ struct _tpl_wayland_egl_display {
 };
 
 struct _tpl_wayland_egl_surface {
+       tpl_object_t base;
        twe_surface_h twe_surface;
        tbm_surface_queue_h tbm_queue;
        tpl_bool_t is_activated;
@@ -337,6 +338,13 @@ __tpl_wl_egl_surface_init(tpl_surface_t *surface)
 
        surface->backend.data = (void *)wayland_egl_surface;
 
+       if (__tpl_object_init(&wayland_egl_surface->base,
+                                                 TPL_OBJECT_SURFACE,
+                                                 NULL) != TPL_ERROR_NONE) {
+               TPL_ERR("Failed to initialize backend surface's base object!");
+               goto object_init_fail;
+       }
+
        twe_surface = twe_surface_add(wayland_egl_display->wl_egl_thread,
                                                                  wayland_egl_display->twe_display,
                                                                  surface->native_handle,
@@ -390,6 +398,7 @@ add_reset_cb_fail:
 queue_create_fail:
        twe_surface_del(twe_surface);
 create_twe_surface_fail:
+object_init_fail:
        free(wayland_egl_surface);
        surface->backend.data = NULL;
        return TPL_ERROR_INVALID_OPERATION;
@@ -407,6 +416,8 @@ __tpl_wl_egl_surface_fini(tpl_surface_t *surface)
        wayland_egl_surface = (tpl_wayland_egl_surface_t *) surface->backend.data;
        TPL_CHECK_ON_NULL_RETURN(wayland_egl_surface);
 
+       TPL_OBJECT_LOCK(wayland_egl_surface);
+
        wayland_egl_display = (tpl_wayland_egl_display_t *)
                                                  surface->display->backend.data;
        TPL_CHECK_ON_NULL_RETURN(wayland_egl_display);
@@ -428,6 +439,8 @@ __tpl_wl_egl_surface_fini(tpl_surface_t *surface)
                wayland_egl_surface->tbm_queue = NULL;
        }
 
+       TPL_OBJECT_UNLOCK(wayland_egl_surface);
+       __tpl_object_fini(&wayland_egl_surface->base);
        free(wayland_egl_surface);
        surface->backend.data = NULL;
 }
@@ -478,12 +491,15 @@ __tpl_wl_egl_surface_enqueue_buffer(tpl_surface_t *surface,
        tpl_result_t ret = TPL_ERROR_NONE;
        int bo_name = 0;
 
+       TPL_OBJECT_LOCK(wayland_egl_surface);
+
        bo_name = tbm_bo_export(tbm_surface_internal_get_bo(tbm_surface, 0));
 
        if (!wayland_egl_surface) {
                TPL_ERR("Invalid parameter. wayland_egl_surface(%p)",
                                wayland_egl_surface);
                TRACE_ASYNC_END((int)tbm_surface, "[DEQ]~[ENQ] BO_NAME:%d", bo_name);
+               TPL_OBJECT_UNLOCK(wayland_egl_surface);
                return TPL_ERROR_INVALID_PARAMETER;
        }
 
@@ -491,6 +507,7 @@ __tpl_wl_egl_surface_enqueue_buffer(tpl_surface_t *surface,
                TPL_ERR("Failed to enqueue tbm_surface(%p) Invalid value.",
                                tbm_surface);
                TRACE_ASYNC_END((int)tbm_surface, "[DEQ]~[ENQ] BO_NAME:%d", bo_name);
+               TPL_OBJECT_UNLOCK(wayland_egl_surface);
                return TPL_ERROR_INVALID_PARAMETER;
        }
 
@@ -530,7 +547,7 @@ __tpl_wl_egl_surface_enqueue_buffer(tpl_surface_t *surface,
                }
 
                TRACE_ASYNC_END((int)tbm_surface, "[DEQ]~[ENQ] BO_NAME:%d", bo_name);
-
+               TPL_OBJECT_UNLOCK(wayland_egl_surface);
                return TPL_ERROR_NONE;
        }
 
@@ -554,10 +571,12 @@ __tpl_wl_egl_surface_enqueue_buffer(tpl_surface_t *surface,
                TPL_ERR("Failed to enqueue tbm_surface(%p). tsq_err=%d",
                                tbm_surface, tsq_err);
                TRACE_ASYNC_END((int)tbm_surface, "[DEQ]~[ENQ] BO_NAME:%d", bo_name);
+               TPL_OBJECT_UNLOCK(wayland_egl_surface);
                return TPL_ERROR_INVALID_OPERATION;
        }
 
        TRACE_ASYNC_END((int)tbm_surface, "[DEQ]~[ENQ] BO_NAME:%d", bo_name);
+       TPL_OBJECT_UNLOCK(wayland_egl_surface);
 
        return TPL_ERROR_NONE;
 }