From: Joonbum Ko Date: Thu, 30 Nov 2023 02:05:54 +0000 (+0900) Subject: remove the duplicate codes from the signal sending X-Git-Tag: accepted/tizen/unified/20240122.175410~14 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0399e2ad3ebc86361047b3bb073f1d225a8de6a0;p=platform%2Fcore%2Fuifw%2Flibtpl-egl.git remove the duplicate codes from the signal sending Change-Id: I303b2293ec399a7107f1c49956e4cb234253e034 Signed-off-by: Joonbum Ko --- diff --git a/src/tpl_wl_egl_thread.c b/src/tpl_wl_egl_thread.c index cdfc538..d4b8902 100755 --- a/src/tpl_wl_egl_thread.c +++ b/src/tpl_wl_egl_thread.c @@ -271,7 +271,9 @@ __cb_wl_egl_buffer_free(tpl_wl_egl_buffer_t *wl_egl_buffer); static tpl_wl_egl_buffer_t * _get_wl_egl_buffer(tbm_surface_h tbm_surface); static int -_write_to_eventfd(int eventfd); +_write_to_eventfd(int eventfd, uint64_t value); +static int +send_signal(int fd, const char *type); static void _thread_wl_egl_surface_init(tpl_wl_egl_surface_t *wl_egl_surface); static tpl_result_t @@ -1620,8 +1622,7 @@ _thread_wl_egl_surface_fini(tpl_wl_egl_surface_t *wl_egl_surface) (struct pst_feedback *)__tpl_list_pop_front( wl_egl_surface->presentation_feedbacks, NULL); if (pst_feedback) { - _write_to_eventfd(pst_feedback->pst_sync_fd); - close(pst_feedback->pst_sync_fd); + send_signal(pst_feedback->pst_sync_fd, "PST_FEEDBACK"); pst_feedback->pst_sync_fd = -1; wp_presentation_feedback_destroy(pst_feedback->presentation_feedback); @@ -1635,11 +1636,8 @@ _thread_wl_egl_surface_fini(tpl_wl_egl_surface_t *wl_egl_surface) wl_egl_surface->presentation_feedbacks = NULL; } - if (wl_egl_surface->presentation_sync.fd != -1) { - _write_to_eventfd(wl_egl_surface->presentation_sync.fd); - close(wl_egl_surface->presentation_sync.fd); - wl_egl_surface->presentation_sync.fd = -1; - } + send_signal(wl_egl_surface->presentation_sync.fd, "PST_SYNC"); + wl_egl_surface->presentation_sync.fd = -1; tpl_gmutex_unlock(&wl_egl_surface->presentation_sync.mutex); @@ -3285,17 +3283,10 @@ __cb_presentation_feedback_presented(void *data, pst_feedback, presentation_feedback, pst_feedback->bo_name); if (pst_feedback->pst_sync_fd != -1) { - int ret = _write_to_eventfd(pst_feedback->pst_sync_fd); - if (ret == -1) { - TPL_ERR("Failed to send presentation_sync signal to fd(%d)", - pst_feedback->pst_sync_fd); - } - TRACE_ASYNC_END(pst_feedback->pst_sync_fd, "[PRESENTATION_SYNC] bo(%d)", pst_feedback->bo_name); - - close(pst_feedback->pst_sync_fd); + send_signal(pst_feedback->pst_sync_fd, "PST_FEEDBACK"); pst_feedback->pst_sync_fd = -1; } @@ -3326,17 +3317,10 @@ __cb_presentation_feedback_discarded(void *data, pst_feedback, presentation_feedback, pst_feedback->bo_name); if (pst_feedback->pst_sync_fd != -1) { - int ret = _write_to_eventfd(pst_feedback->pst_sync_fd); - if (ret == -1) { - TPL_ERR("Failed to send presentation_sync signal to fd(%d)", - pst_feedback->pst_sync_fd); - } - TRACE_ASYNC_END(pst_feedback->pst_sync_fd, "[PRESENTATION_SYNC] bo(%d)", pst_feedback->bo_name); - - close(pst_feedback->pst_sync_fd); + send_signal(pst_feedback->pst_sync_fd, "PST_FEEDBACK"); pst_feedback->pst_sync_fd = -1; } @@ -3449,8 +3433,7 @@ _thread_wl_surface_commit(tpl_wl_egl_surface_t *wl_egl_surface, } else { TPL_ERR("Failed to create presentation feedback. wl_egl_buffer(%p)", wl_egl_buffer); - _write_to_eventfd(wl_egl_buffer->presentation_sync_fd); - close(wl_egl_buffer->presentation_sync_fd); + send_signal(wl_egl_buffer->presentation_sync_fd, "PST_SYNC"); wl_egl_buffer->presentation_sync_fd = -1; } } @@ -3577,17 +3560,11 @@ _thread_wl_surface_commit(tpl_wl_egl_surface_t *wl_egl_surface, tpl_gmutex_lock(&wl_egl_surface->commit_sync.mutex); if (wl_egl_buffer->commit_sync_fd != -1) { - int ret = _write_to_eventfd(wl_egl_buffer->commit_sync_fd); - if (ret == -1) { - TPL_ERR("Failed to send commit_sync signal to fd(%d)", wl_egl_buffer->commit_sync_fd); - } - TRACE_ASYNC_END(wl_egl_buffer->commit_sync_fd, "[COMMIT_SYNC] bo(%d)", wl_egl_buffer->bo_name); TPL_LOG_D("[COMMIT_SYNC][SEND]", "wl_egl_surface(%p) commit_sync_fd(%d)", wl_egl_surface, wl_egl_buffer->commit_sync_fd); - - close(wl_egl_buffer->commit_sync_fd); + send_signal(wl_egl_buffer->commit_sync_fd, "COMMIT_SYNC"); wl_egl_buffer->commit_sync_fd = -1; } @@ -3595,16 +3572,10 @@ _thread_wl_surface_commit(tpl_wl_egl_surface_t *wl_egl_surface, } static int -_write_to_eventfd(int eventfd) +_write_to_eventfd(int eventfd, uint64_t value) { - uint64_t value = 1; int ret; - if (eventfd == -1) { - TPL_ERR("Invalid fd(-1)"); - return -1; - } - ret = write(eventfd, &value, sizeof(uint64_t)); if (ret == -1) { TPL_ERR("failed to write to fd(%d)", eventfd); @@ -3614,6 +3585,20 @@ _write_to_eventfd(int eventfd) return ret; } +static int send_signal(int fd, const char *type) +{ + int ret = 0; + if (fd < 0) return ret; + + ret = _write_to_eventfd(fd, 1); + if (ret < 0) + TPL_ERR("Failed to send %s signal to fd(%d)", type, fd); + + close(fd); + + return ret; +} + void __tpl_display_init_backend_wl_egl_thread(tpl_display_backend_t *backend) { @@ -3711,23 +3696,11 @@ __cb_wl_egl_buffer_free(tpl_wl_egl_buffer_t *wl_egl_buffer) wl_egl_buffer->waiting_source = NULL; } - if (wl_egl_buffer->commit_sync_fd != -1) { - int ret = _write_to_eventfd(wl_egl_buffer->commit_sync_fd); - if (ret == -1) - TPL_ERR("Failed to send commit_sync signal to fd(%d)", - wl_egl_buffer->commit_sync_fd); - close(wl_egl_buffer->commit_sync_fd); - wl_egl_buffer->commit_sync_fd = -1; - } + send_signal(wl_egl_buffer->commit_sync_fd, "COMMIT_SYNC"); + wl_egl_buffer->commit_sync_fd = -1; - if (wl_egl_buffer->presentation_sync_fd != -1) { - int ret = _write_to_eventfd(wl_egl_buffer->presentation_sync_fd); - if (ret == -1) - TPL_ERR("Failed to send presentation_sync signal to fd(%d)", - wl_egl_buffer->presentation_sync_fd); - close(wl_egl_buffer->presentation_sync_fd); - wl_egl_buffer->presentation_sync_fd = -1; - } + send_signal(wl_egl_buffer->presentation_sync_fd, "PST_SYNC"); + wl_egl_buffer->presentation_sync_fd = -1; if (wl_egl_buffer->rects) { free(wl_egl_buffer->rects);