}
void
-tpl_gsource_destroy(tpl_gsource *source)
+tpl_gsource_destroy(tpl_gsource *source, tpl_bool_t destroy_in_thread)
{
if (g_source_is_destroyed(&source->gsource)) {
TPL_WARN("gsource(%p) already has been destroyed.",
return;
}
- if (source->type == SOURCE_TYPE_NORMAL &&
- source->finalizer != NULL) {
- g_mutex_lock(&source->thread->thread_mutex);
+ if (destroy_in_thread) {
+ if (source->type == SOURCE_TYPE_NORMAL) {
+ g_mutex_lock(&source->thread->thread_mutex);
- tpl_gsource_send_event(source->finalizer, 1);
-
- g_cond_wait(&source->thread->thread_cond, &source->thread->thread_mutex);
- g_mutex_unlock(&source->thread->thread_mutex);
- }
+ tpl_gsource_send_event(source->finalizer, 1);
+ g_cond_wait(&source->thread->thread_cond, &source->thread->thread_mutex);
+ g_mutex_unlock(&source->thread->thread_mutex);
+ }
+ } else {
+ if (source->type == SOURCE_TYPE_NORMAL &&
+ source->finalizer) {
+ tpl_gsource *finalize = source->finalizer;
+ g_source_remove_unix_fd(&finalize->gsource, finalize->tag);
+ g_source_destroy(&finalize->gsource);
+ g_source_unref(&finalize->gsource);
+ source->finalizer = NULL;
+ }
- if (!g_source_is_destroyed(&source->gsource) &&
- !(source->type == SOURCE_TYPE_DISPOSABLE ||
- source->type == SOURCE_TYPE_FINALIZER)) {
g_source_remove_unix_fd(&source->gsource, source->tag);
g_source_destroy(&source->gsource);
g_source_unref(&source->gsource);
* Detach the passed tpl_gsource from thread and destroy it.
*
* @param source Pointer to tpl_gsource to destroy.
+ * @param destroy_in_thread TRUE if destroy in thread through eventfd, FALSE otherwise.
+ * It is valid only when SOURCE_TYPE is NORMAL.
+ * @see tpl_gsource_type_t tpl_gsource_create
*/
void
-tpl_gsource_destroy(tpl_gsource *source);
+tpl_gsource_destroy(tpl_gsource *source, tpl_bool_t destroy_in_thread);
/**
* Send an event to dispatch the gsource attached to the thread.
tdm_err);
TPL_WARN("tdm_source(%p) will be removed from thread.", gsource);
- tpl_gsource_destroy(gsource);
+ tpl_gsource_destroy(gsource, TPL_FALSE);
wl_egl_display->tdm_source = NULL;
tpl_wl_egl_display_t *wl_egl_display = (tpl_wl_egl_display_t *)data;
if (wl_egl_display->tdm_initialized)
- tpl_gsource_destroy(wl_egl_display->tdm_source);
+ tpl_gsource_destroy(wl_egl_display->tdm_source, TPL_FALSE);
if (wl_egl_display->wl_initialized)
_thread_wl_display_fini(wl_egl_display);
}
free_display:
if (wl_egl_display->thread) {
- tpl_gsource_destroy(wl_egl_display->tdm_source);
+ tpl_gsource_destroy(wl_egl_display->tdm_source, TPL_TRUE);
tpl_gthread_destroy(wl_egl_display->thread, _thread_fini);
}
wl_egl_display->wl_display);
if (wl_egl_display->gsource) {
- tpl_gsource_destroy(wl_egl_display->gsource);
+ tpl_gsource_destroy(wl_egl_display->gsource, TPL_TRUE);
wl_egl_display->gsource = NULL;
}
if (wl_egl_display->tdm_source && wl_egl_display->tdm_initialized) {
- tpl_gsource_destroy(wl_egl_display->tdm_source);
+ tpl_gsource_destroy(wl_egl_display->tdm_source, TPL_TRUE);
wl_egl_display->tdm_source = NULL;
}