From 169c9152399e169cc74005c8c14ed9a52e126467 Mon Sep 17 00:00:00 2001 From: "joonbum.ko" Date: Wed, 17 Jan 2018 11:40:16 +0900 Subject: [PATCH] tpl_wayland_egl_thread: Changed to use GMutex instead of tpl_object of the surf_source. Change-Id: I05bdca4011f142fd39db939de49a9d83db55259c Signed-off-by: joonbum.ko --- src/tpl_wayland_egl_thread.c | 54 ++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 1a69167..cc3e2e8 100644 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -104,7 +104,6 @@ struct _twe_wl_surf_source { } swapchain_properties; tpl_surface_cb_func_t rotate_cb; tpl_bool_t rotation_capability; - tpl_object_t obj; /* for mutex lock */ tpl_list_t *committed_buffers; tpl_list_t *in_use_buffers; tpl_list_t *vblank_waiting_buffers; /* for FIFO/FIFO_RELAXED modes */ @@ -117,6 +116,8 @@ struct _twe_wl_surf_source { twe_wl_disp_source *disp_source; twe_del_source *surf_del_source; + GMutex surf_mutex; + GMutex free_queue_mutex; GCond free_queue_cond; @@ -1123,12 +1124,12 @@ __cb_destroy_callback(void *private) if (surf_source) { TPL_LOG_T(BACKEND, "[DESTROY_CB] wl_egl_window(%p) surf_source(%p)", surf_source->wl_egl_window, surf_source); - TPL_OBJECT_LOCK(&surf_source->obj); + g_mutex_lock(&surf_source->surf_mutex); surf_source->wl_egl_window->private = NULL; surf_source->wl_egl_window = NULL; surf_source->surf = NULL; surf_source->is_destroying = TPL_TRUE; - TPL_OBJECT_UNLOCK(&surf_source->obj); + g_mutex_unlock(&surf_source->surf_mutex); } } @@ -1279,11 +1280,11 @@ __cb_buffer_release_callback(void *data, struct wl_proxy *wl_buffer) TPL_ERR("tbm_surface(%p) tsq_err(%d)", tbm_surface, tsq_err); if (surf_source->committed_buffers) { - TPL_OBJECT_LOCK(&surf_source->obj); + g_mutex_lock(&surf_source->surf_mutex); __tpl_list_remove_data(surf_source->committed_buffers, (void *)tbm_surface, TPL_FIRST, NULL); - TPL_OBJECT_UNLOCK(&surf_source->obj); + g_mutex_unlock(&surf_source->surf_mutex); } buf_info->need_to_release = TPL_FALSE; @@ -1308,11 +1309,11 @@ __cb_buffer_release_callback(void *data, struct wl_proxy *wl_buffer) g_mutex_lock(&surf_source->free_queue_mutex); if (surf_source->committed_buffers) { - TPL_OBJECT_LOCK(&surf_source->obj); + g_mutex_lock(&surf_source->surf_mutex); __tpl_list_remove_data(surf_source->committed_buffers, (void *)tbm_surface, TPL_FIRST, NULL); - TPL_OBJECT_UNLOCK(&surf_source->obj); + g_mutex_unlock(&surf_source->surf_mutex); } TRACE_MARK("[RELEASE] BO(%d)", @@ -1389,10 +1390,10 @@ _twe_surface_set_wl_buffer_info(twe_wl_surf_source *surf_source, buf_info->sync_fd = -1; if (surf_source->in_use_buffers) { - TPL_OBJECT_LOCK(&surf_source->obj); + g_mutex_lock(&surf_source->surf_mutex); __tpl_list_push_back(surf_source->in_use_buffers, (void *)tbm_surface); - TPL_OBJECT_UNLOCK(&surf_source->obj); + g_mutex_unlock(&surf_source->surf_mutex); } TRACE_MARK("[SET_BUFFER_INFO] BO(%d)", @@ -1485,10 +1486,10 @@ _twe_surface_set_wl_buffer_info(twe_wl_surf_source *surf_source, buf_info); if (surf_source->in_use_buffers) { - TPL_OBJECT_LOCK(&surf_source->obj); + g_mutex_lock(&surf_source->surf_mutex); __tpl_list_push_back(surf_source->in_use_buffers, (void *)tbm_surface); - TPL_OBJECT_UNLOCK(&surf_source->obj); + g_mutex_unlock(&surf_source->surf_mutex); } TRACE_MARK("[SET_BUFFER_INFO] BO(%d)", @@ -1524,11 +1525,11 @@ _twe_surface_cancel_dequeued_buffer(twe_wl_surf_source *surf_source, tbm_surface); if (surf_source->in_use_buffers) { - TPL_OBJECT_LOCK(&surf_source->obj); + g_mutex_lock(&surf_source->surf_mutex); /* Stop tracking of this canceled tbm_surface */ __tpl_list_remove_data(surf_source->in_use_buffers, (void *)tbm_surface, TPL_FIRST, NULL); - TPL_OBJECT_UNLOCK(&surf_source->obj); + g_mutex_unlock(&surf_source->surf_mutex); } } @@ -1645,7 +1646,7 @@ __cb_tdm_client_wait_vblank(tdm_client_vblank *vblank, tdm_error error, if (!disp_source->is_vulkan_dpy) _twe_thread_wl_surface_acquire_and_commit(surf_source); else { - TPL_OBJECT_LOCK(&surf_source->obj); + g_mutex_lock(&surf_source->surf_mutex); switch (surf_source->swapchain_properties.present_mode) { case TPL_DISPLAY_PRESENT_MODE_MAILBOX: if (surf_source->draw_done_buffer) { @@ -1686,7 +1687,7 @@ __cb_tdm_client_wait_vblank(tdm_client_vblank *vblank, tdm_error error, break; } - TPL_OBJECT_UNLOCK(&surf_source->obj); + g_mutex_unlock(&surf_source->surf_mutex); } } @@ -1928,7 +1929,7 @@ _twe_thread_wl_surface_acquire_and_commit(twe_wl_surf_source *surf_source) tbm_surface_internal_get_user_data(tbm_surface, KEY_BUFFER_INFO, (void **)&buf_info); - TPL_OBJECT_LOCK(&surf_source->obj); + g_mutex_lock(&surf_source->surf_mutex); if (!disp_source->is_vulkan_dpy) { /* wayland_egl */ TPL_LOG_T(BACKEND, "[ACQ] tbm_surface(%p) bo(%d)", tbm_surface, @@ -1996,7 +1997,7 @@ _twe_thread_wl_surface_acquire_and_commit(twe_wl_surf_source *surf_source) break; } } - TPL_OBJECT_UNLOCK(&surf_source->obj); + g_mutex_unlock(&surf_source->surf_mutex); } } @@ -2048,8 +2049,6 @@ _twe_thread_wl_surface_finalize(GSource *source) close(surf_source->event_fd); surf_source->event_fd = -1; - __tpl_object_fini(&surf_source->obj); - return; } @@ -2242,6 +2241,8 @@ _twe_thread_wl_surf_source_destroy(void *source) g_mutex_lock(&disp_source->wl_event_mutex); + g_mutex_lock(&surf_source->surf_mutex); + if (surf_source->in_use_buffers) { __tpl_list_free(surf_source->in_use_buffers, (tpl_free_func_t)__cb_buffer_remove_from_list); @@ -2298,6 +2299,9 @@ _twe_thread_wl_surf_source_destroy(void *source) surf_source->surf = NULL; } + g_mutex_unlock(&surf_source->surf_mutex); + g_mutex_clear(&surf_source->surf_mutex); + g_mutex_unlock(&disp_source->wl_event_mutex); g_cond_clear(&surf_source->free_queue_cond); @@ -2397,8 +2401,6 @@ twe_surface_add(twe_thread* thread, source->vk_sub_thread = NULL; source->draw_done_count = 0; - __tpl_object_init(&source->obj, TPL_OBJECT_SURFACE, NULL); - if (!disp_source->is_vulkan_dpy) { struct wl_egl_window *wl_egl_window = (struct wl_egl_window *)native_handle; @@ -2430,6 +2432,8 @@ twe_surface_add(twe_thread* thread, g_source_attach(&source->gsource, g_main_loop_get_context(ctx->twe_loop)); + g_mutex_init(&source->surf_mutex); + g_mutex_init(&source->free_queue_mutex); g_cond_init(&source->free_queue_cond); @@ -2662,7 +2666,7 @@ twe_surface_destroy_swapchain(twe_surface_h twe_surface) } if (surf_source->committed_buffers) { - TPL_OBJECT_LOCK(&surf_source->obj); + g_mutex_lock(&surf_source->surf_mutex); while (!__tpl_list_is_empty(surf_source->committed_buffers)) { tbm_surface_queue_error_e tsq_err = TBM_SURFACE_QUEUE_ERROR_NONE; tbm_surface_h tbm_surface = @@ -2677,7 +2681,7 @@ twe_surface_destroy_swapchain(twe_surface_h twe_surface) TPL_ERR("Failed to release. tbm_surface(%p) tsq_err(%d)", tbm_surface, tsq_err); } - TPL_OBJECT_UNLOCK(&surf_source->obj); + g_mutex_unlock(&surf_source->surf_mutex); } if (surf_source->tbm_queue) { @@ -2863,13 +2867,13 @@ twe_surface_commit_without_enqueue(twe_surface_h twe_surface, return; } - TPL_OBJECT_LOCK(&surf_source->obj); + g_mutex_lock(&surf_source->surf_mutex); if (!surf_source->is_destroying) _twe_thread_wl_surface_commit(surf_source, tbm_surface); else TPL_WARN("surf_source(%p) native window is already destroyed.", surf_source); - TPL_OBJECT_UNLOCK(&surf_source->obj); + g_mutex_unlock(&surf_source->surf_mutex); } static gboolean -- 2.7.4