static gpointer
_tpl_gthread_init(gpointer data)
{
- tpl_gthread *thread = data;
+ tpl_gthread *thread = (tpl_gthread *)data;
g_mutex_lock(&thread->thread_mutex);
g_cond_signal(&thread->thread_cond);
g_mutex_unlock(&thread->thread_mutex);
- g_main_loop_run(thread->twe_loop);
+ g_main_loop_run(thread->loop);
return thread;
}
-static void
-_tpl_gthread_fini(gpointer data)
+static tpl_bool_t
+_tpl_gthread_fini(tpl_gsource *source, uint64_t message)
{
- tpl_gthread *thread = data;
+ tpl_gthread *thread = (tpl_gthread *)source->data;
+
+ TPL_IGNORE(message);
g_mutex_lock(&thread->thread_mutex);
thread->deinit_func(thread->func_data);
g_cond_signal(&thread->thread_cond);
- g_mutex_unlock(&thread->thread_mutex);
+ g_mutex_unlock(&thread->thread_mutex);
+
+ return TPL_FALSE;
}
static tpl_gsource_functions thread_destroy_funcs = {
g_mutex_lock(&new_thread->thread_mutex);
new_thread->destroy_sig_source =
tpl_gsource_create(new_thread, new_thread, -1,
- &thread_destroy_funcs, TPL_TRUE);
+ &thread_destroy_funcs, SOURCE_TYPE_FINALIZER);
new_thread->loop = loop;
new_thread->init_func = init_func;
g_thread_join(thread->thread);
g_main_loop_unref(thread->loop);
+ thread->loop = NULL;
+
g_mutex_unlock(&thread->thread_mutex);
g_mutex_clear(&thread->thread_mutex);
g_cond_clear(&thread->thread_cond);
- thread->func = NULL;
+ thread->func_data = NULL;
+ thread->thread = NULL;
free(thread);
thread = NULL;
_thread_source_dispatch(GSource *source, GSourceFunc cb, gpointer data)
{
tpl_gsource *gsource = (tpl_gsource *)source;
- tpl_bool_t ret = TPL_GSOURCE_CONTINUE;
+ gboolean ret = G_SOURCE_CONTINUE;
GIOCondition cond = g_source_query_unix_fd(source, gsource->tag);
TPL_IGNORE(cb);
g_source_unref(&del_source->gsource);
g_cond_signal(&del_source->thread->thread_cond);
- g_mutex_unlock(&del_source->thread_mutex);
+ g_mutex_unlock(&del_source->thread->thread_mutex);
}
}
} else {
g_source_remove_unix_fd(&gsource->gsource, gsource->tag);
g_source_destroy(&gsource->gsource);
g_source_unref(&gsource->gsource);
- ret = TPL_GSOURCE_REMOVE;
+ ret = G_SOURCE_REMOVE;
}
return ret;
void *
tpl_gsource_get_data(tpl_gsource *source)
{
- if (source && source->data)
- return source->data;
+ void *data = NULL;
+
+ if (source)
+ data = source->data;
+
+ return data;
}
tpl_bool_t
return TPL_FALSE;
}
- cond = g_source_query_unix_fd(source->gsource, source->tag);
+ cond = g_source_query_unix_fd(&source->gsource, source->tag);
if (cond & G_IO_IN)
return TPL_TRUE;
typedef struct _tpl_gsource tpl_gsource;
typedef struct _tpl_gsource_functions tpl_gsource_functions;
-typedef TPL_TRUE TPL_GSOURCE_CONTINUE;
-typedef TPL_FALSE TPL_GSOURCE_REMOVE;
-
typedef void (*tpl_gthread_func) (void *user_data);
typedef GMutex tpl_gmutex;
*/
tpl_gthread *
tpl_gthread_create(const char *thread_name,
- tpl_gthread_init_func init_func, void *func_data);
+ tpl_gthread_func init_func, void *func_data);
/**
* Stop thread and Destroy tpl_gthread