From 479bcb365cf633141d9c15f40afa3143dcf4915f Mon Sep 17 00:00:00 2001 From: "joonbum.ko" Date: Wed, 13 Sep 2017 16:59:59 +0900 Subject: [PATCH] tpl_wl_egl_thread: Modified to ensure thread safety between enqueue and destroy. Change-Id: I36af6adb3956112093ddcd2304f31b5ab26705f3 Signed-off-by: joonbum.ko --- src/tpl_wl_egl_thread.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/tpl_wl_egl_thread.c b/src/tpl_wl_egl_thread.c index 43c093b..0a590ca 100644 --- a/src/tpl_wl_egl_thread.c +++ b/src/tpl_wl_egl_thread.c @@ -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; } -- 2.7.4