- This can remove the gsource registered in a specific GMainContext.
Change-Id: I2d0b1f15da0270a1e17577e045bcd06092689a76
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() +
>hread->idle_mutex,
end_time);
if (!ret) {
+ tpl_gsource_remove(gthread, id);
TPL_ERR("wait_idle timeout!");
res = TPL_ERROR_TIME_OUT;
break;
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);
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);
}
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;
* @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);
__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);
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)
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;
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;
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)
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);
}