tpl_gsource_type_t type;
tpl_gsource *finalizer;
+ tpl_bool_t intended_destroy;
void *data;
};
+static void
+__gsource_remove_and_destroy(tpl_gsource *source);
static gpointer
_tpl_gthread_init(gpointer data)
if (gsource->gsource_funcs && gsource->gsource_funcs->dispatch)
ret = gsource->gsource_funcs->dispatch(gsource, message);
- if (gsource->type == SOURCE_TYPE_FINALIZER) {
+ if (gsource->type == SOURCE_TYPE_FINALIZER &&
+ 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);
- g_source_remove_unix_fd(&del_source->gsource, del_source->tag);
- g_source_destroy(&del_source->gsource);
- g_source_unref(&del_source->gsource);
+ __gsource_remove_and_destroy(del_source);
g_cond_signal(&thread->thread_cond);
g_mutex_unlock(&thread->thread_mutex);
if (gsource->type == SOURCE_TYPE_DISPOSABLE ||
gsource->type == SOURCE_TYPE_FINALIZER) {
- g_source_remove_unix_fd(&gsource->gsource, gsource->tag);
- g_source_destroy(&gsource->gsource);
- g_source_unref(&gsource->gsource);
+ __gsource_remove_and_destroy(gsource);
ret = G_SOURCE_REMOVE;
}
new_gsource->gsource_funcs = funcs;
new_gsource->data = data;
new_gsource->type = type;
+ new_gsource->intended_destroy = TPL_FALSE;
if (new_gsource->type == SOURCE_TYPE_NORMAL) {
tpl_gsource *finalizer = tpl_gsource_create(thread, new_gsource, -1,
return new_gsource;
}
+static void
+__gsource_remove_and_destroy(tpl_gsource *source)
+{
+ TPL_DEBUG("[GSOURCE_DESTROY] tpl_gsource(%p) type(%d)",
+ source, source->type);
+
+ g_source_remove_unix_fd(&source->gsource, source->tag);
+ g_source_destroy(&source->gsource);
+ g_source_unref(&source->gsource);
+}
+
void
tpl_gsource_destroy(tpl_gsource *source, tpl_bool_t destroy_in_thread)
{
return;
}
- TPL_DEBUG("[GSOURCE_DESTROY] tpl_gsource(%p) type(%d)",
- source, source->type);
+ if (source->type == SOURCE_TYPE_NORMAL &&
+ source->finalizer) {
+ tpl_gsource *finalizer = source->finalizer;
- if (destroy_in_thread) {
- tpl_gthread *thread = source->thread;
- if (source->type == SOURCE_TYPE_NORMAL) {
+ if (destroy_in_thread) {
+ tpl_gthread *thread = source->thread;
g_mutex_lock(&thread->thread_mutex);
- tpl_gsource_send_message(source->finalizer, 1);
+ 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 {
- 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);
+ } else {
+ __gsource_remove_and_destroy(finalizer);
source->finalizer = NULL;
}
+ }
- g_source_remove_unix_fd(&source->gsource, source->tag);
- g_source_destroy(&source->gsource);
- g_source_unref(&source->gsource);
+ if (!destroy_in_thread) {
+ __gsource_remove_and_destroy(source);
}
}