tpl_gsource *gsource = (tpl_gsource *)source;
gboolean ret = G_SOURCE_CONTINUE;
GIOCondition cond = g_source_query_unix_fd(source, gsource->tag);
+ tpl_gthread *thread = gsource->thread;
TPL_IGNORE(cb);
gsource->intended_destroy == TPL_TRUE) {
tpl_gsource *del_source = (tpl_gsource *)gsource->data;
if (!g_source_is_destroyed(&del_source->gsource)) {
- tpl_gthread *thread = del_source->thread;
g_mutex_lock(&thread->thread_mutex);
__gsource_remove_and_destroy(del_source);
if (gsource->type == SOURCE_TYPE_DISPOSABLE ||
gsource->type == SOURCE_TYPE_FINALIZER) {
+ g_mutex_lock(&thread->thread_mutex);
__gsource_remove_and_destroy(gsource);
ret = G_SOURCE_REMOVE;
+ g_mutex_unlock(&thread->thread_mutex);
}
return ret;
static void
__gsource_remove_and_destroy(tpl_gsource *source)
{
+ if (g_source_is_destroyed(&source->gsource))
+ return;
+
TPL_DEBUG("[GSOURCE_DESTROY] tpl_gsource(%p) type(%d)",
source, source->type);
void
tpl_gsource_destroy(tpl_gsource *source, tpl_bool_t destroy_in_thread)
{
+ tpl_gthread *thread = source->thread;
+
if (g_source_is_destroyed(&source->gsource)) {
TPL_WARN("gsource(%p) already has been destroyed.",
source);
return;
}
+ g_mutex_lock(&thread->thread_mutex);
if (source->type == SOURCE_TYPE_NORMAL &&
source->finalizer) {
tpl_gsource *finalizer = source->finalizer;
if (destroy_in_thread) {
- tpl_gthread *thread = source->thread;
- g_mutex_lock(&thread->thread_mutex);
-
finalizer->intended_destroy = TPL_TRUE;
tpl_gsource_send_message(finalizer, 1);
g_cond_wait(&thread->thread_cond, &thread->thread_mutex);
- g_mutex_unlock(&thread->thread_mutex);
} else {
__gsource_remove_and_destroy(finalizer);
source->finalizer = NULL;
if (!destroy_in_thread) {
__gsource_remove_and_destroy(source);
}
+ g_mutex_unlock(&thread->thread_mutex);
}
void