From: TaeHyeon Jeong Date: Thu, 10 Oct 2024 05:40:01 +0000 (+0900) Subject: tpl: Add tpl_gsource_remove() X-Git-Tag: accepted/tizen/unified/20241017.114708~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F82%2F318882%2F1;p=platform%2Fcore%2Fuifw%2Flibtpl-egl.git tpl: Add tpl_gsource_remove() - This can remove the gsource registered in a specific GMainContext. Change-Id: I2d0b1f15da0270a1e17577e045bcd06092689a76 --- diff --git a/src/tpl_utils_gthread.c b/src/tpl_utils_gthread.c index 1befeda..a5c77bd 100644 --- a/src/tpl_utils_gthread.c +++ b/src/tpl_utils_gthread.c @@ -531,12 +531,13 @@ tpl_gthread_wait_idle(tpl_gthread *gthread) gint64 end_time; gboolean ret = TRUE; tpl_result_t res = TPL_ERROR_NONE; + tpl_gid_t id; TPL_LOG_D("[WAIT_IDLE]", "BEGIN"); g_mutex_lock(>hread->idle_mutex); - tpl_gthread_add_idle(gthread, (tpl_gsource_func)_thread_idle_cb, gthread); + id = tpl_gthread_add_idle(gthread, (tpl_gsource_func)_thread_idle_cb, gthread); /* 500ms timeout */ end_time = g_get_monotonic_time() + @@ -546,6 +547,7 @@ tpl_gthread_wait_idle(tpl_gthread *gthread) >hread->idle_mutex, end_time); if (!ret) { + tpl_gsource_remove(gthread, id); TPL_ERR("wait_idle timeout!"); res = TPL_ERROR_TIME_OUT; break; @@ -609,15 +611,16 @@ tpl_gthread_continue(tpl_gthread *gthread) g_mutex_unlock(>hread->pause_mutex); } -tpl_result_t +tpl_gid_t tpl_gthread_add_idle(tpl_gthread *gthread, tpl_gsource_func idle_cb, void *data) { TPL_CHECK_ON_NULL_RETURN_VAL(gthread, TPL_ERROR_INVALID_PARAMETER); + tpl_gid_t id; GSource *idle_source = g_idle_source_new(); if (idle_source == NULL) { TPL_WARN("Failed to create and attach idle source"); - return TPL_ERROR_INVALID_OPERATION; + return 0; // failure } g_source_set_priority(idle_source, G_PRIORITY_DEFAULT + 10); @@ -626,9 +629,19 @@ tpl_gthread_add_idle(tpl_gthread *gthread, tpl_gsource_func idle_cb, void *data) NULL); g_mutex_lock(>hread->thread_mutex); - g_source_attach(idle_source, g_main_loop_get_context(gthread->loop)); + id = g_source_attach(idle_source, g_main_loop_get_context(gthread->loop)); g_mutex_unlock(>hread->thread_mutex); g_source_unref(idle_source); - return TPL_ERROR_NONE; + return id; +} + +void +tpl_gsource_remove(tpl_gthread *gthread, tpl_gid_t id) +{ + GMainContext *context = g_main_loop_get_context(gthread->loop); + GSource *source = g_main_context_find_source_by_id(context, id); + + if (source) + g_source_destroy(source); } diff --git a/src/tpl_utils_gthread.h b/src/tpl_utils_gthread.h index 304fa74..888e4a2 100644 --- a/src/tpl_utils_gthread.h +++ b/src/tpl_utils_gthread.h @@ -10,6 +10,7 @@ typedef struct _tpl_gthread tpl_gthread; typedef struct _tpl_gsource tpl_gsource; typedef struct _tpl_gsource_functions tpl_gsource_functions; +typedef guint tpl_gid_t; typedef void (*tpl_gthread_func) (void *user_data); //typedef GSourceFunc tpl_gsource_func; @@ -299,11 +300,16 @@ tpl_gthread_continue(tpl_gthread *gthread); * @param callback Callback function to be called on idle * @param data User data to pass to idle callback * - * @return tpl_result_t result of add idle source + * @return ID(0 means failure) for the source within the gthread */ -tpl_result_t +tpl_gid_t tpl_gthread_add_idle(tpl_gthread *gthread, tpl_gsource_func idle_cb, void *data); - - - +/** + * remove the source by id from a specific tpl_gthread + * + * @param gthread Pointer to tpl_gthread + * @param id ID of the source to remove +*/ +void +tpl_gsource_remove(tpl_gthread *gthread, tpl_gid_t id); diff --git a/src/tpl_wl_egl_thread.c b/src/tpl_wl_egl_thread.c index 763959f..76e602f 100755 --- a/src/tpl_wl_egl_thread.c +++ b/src/tpl_wl_egl_thread.c @@ -2445,6 +2445,7 @@ static void __tpl_wl_egl_surface_fini(tpl_surface_t *surface) { tpl_wl_egl_display_t *wl_egl_display = NULL; + tpl_gid_t id; TPL_ASSERT(surface); TPL_ASSERT(surface->display); @@ -2468,8 +2469,8 @@ __tpl_wl_egl_surface_fini(tpl_surface_t *surface) wl_egl_surface->need_force_release = TPL_FALSE; wl_egl_surface->buffers_finalize_done = TPL_FALSE; - tpl_gthread_add_idle(wl_egl_display->thread, - __idle_cb_buffers_finalize, wl_egl_surface); + id = tpl_gthread_add_idle(wl_egl_display->thread, + __idle_cb_buffers_finalize, wl_egl_surface); tpl_gcond_timed_wait(&wl_egl_surface->surf_cond, &wl_egl_surface->surf_mutex, BUFFER_CLEAR_WAITING_TIMEOUT_MS) @@ -2477,6 +2478,7 @@ __tpl_wl_egl_surface_fini(tpl_surface_t *surface) if (wl_egl_surface->buffers_finalize_done) break; } else { + tpl_gsource_remove(wl_egl_display->thread, id); TPL_WARN("buffer clear timeout. wl_egl_surface(%p)", wl_egl_surface); wl_egl_surface->buffers_finalize_done = TPL_TRUE; @@ -2852,6 +2854,7 @@ __tpl_wl_egl_surface_dequeue_buffer(tpl_surface_t *surface, uint64_t timeout_ns, tpl_wl_egl_surface_t wl_egl_surface(surface->backend.data); tpl_wl_egl_display_t wl_egl_display(surface->display->backend.data); tpl_wl_egl_buffer_t *wl_egl_buffer = NULL; + tpl_gid_t id; tbm_surface_queue_error_e tsq_err = TBM_SURFACE_QUEUE_ERROR_NONE; int bo_name = 0; @@ -2864,8 +2867,8 @@ __tpl_wl_egl_surface_dequeue_buffer(tpl_surface_t *surface, uint64_t timeout_ns, tpl_gmutex_lock(&wl_egl_surface->surf_mutex); if (wl_egl_surface->reset == TPL_TRUE) { wl_egl_surface->buffers_commit_done = TPL_FALSE; - tpl_gthread_add_idle(wl_egl_display->thread, - __idle_cb_check_buffers_commit, wl_egl_surface); + id = tpl_gthread_add_idle(wl_egl_display->thread, + __idle_cb_check_buffers_commit, wl_egl_surface); tpl_gcond_timed_wait(&wl_egl_surface->surf_cond, &wl_egl_surface->surf_mutex, CHECK_COMMIT_TIMEOUT_MS) @@ -2873,6 +2876,7 @@ __tpl_wl_egl_surface_dequeue_buffer(tpl_surface_t *surface, uint64_t timeout_ns, if (wl_egl_surface->buffers_commit_done) break; } else { + tpl_gsource_remove(wl_egl_display->thread, id); TPL_WARN("wl_egl_surface(%p) timeout error occured", wl_egl_surface); _print_buffer_lists(wl_egl_surface); }