GMutex pause_mutex;
tpl_bool_t is_idle;
tpl_bool_t paused;
+ tpl_bool_t init_done;
tpl_gthread_func init_func;
void *func_data;
if (thread->init_func)
thread->init_func(thread->func_data);
+ thread->init_done = TPL_TRUE;
g_cond_signal(&thread->thread_cond);
g_mutex_unlock(&thread->thread_mutex);
new_thread->is_idle = TPL_FALSE;
new_thread->paused = TPL_FALSE;
+ new_thread->init_done = TPL_FALSE;
g_mutex_lock(&new_thread->thread_mutex);
new_thread->func_data = func_data;
new_thread->thread = g_thread_new(thread_name,
_tpl_gthread_init, new_thread);
- g_cond_wait(&new_thread->thread_cond,
- &new_thread->thread_mutex);
+
+ while (!new_thread->init_done) {
+ g_cond_wait(&new_thread->thread_cond,
+ &new_thread->thread_mutex);
+ }
g_mutex_unlock(&new_thread->thread_mutex);
ssize_t s;
uint64_t message = 0;
+ g_mutex_lock(&thread->thread_mutex);
if (gsource->fd_type == FD_TYPE_EVENT) {
s = read(gsource->fd, &message, sizeof(uint64_t));
if (s != sizeof(uint64_t)) {
gsource->fd);
}
}
+ g_mutex_unlock(&thread->thread_mutex);
if (gsource->gsource_funcs && gsource->gsource_funcs->dispatch)
ret = gsource->gsource_funcs->dispatch(gsource, message);
gsource->intended_destroy == TPL_TRUE) {
tpl_gsource *del_source = (tpl_gsource *)gsource->data;
if (!g_source_is_destroyed(&del_source->gsource)) {
- g_mutex_lock(&thread->thread_mutex);
-
__gsource_remove_and_destroy(del_source);
__gsource_remove_and_destroy(gsource);
-
- g_cond_signal(&thread->thread_cond);
- g_mutex_unlock(&thread->thread_mutex);
-
return G_SOURCE_REMOVE;
}
}
}
if (gsource->type == SOURCE_TYPE_DISPOSABLE) {
- g_mutex_lock(&thread->thread_mutex);
__gsource_remove_and_destroy(gsource);
- ret = G_SOURCE_REMOVE;
- g_mutex_unlock(&thread->thread_mutex);
}
return ret;
return;
}
- g_mutex_lock(&thread->thread_mutex);
if (source->type == SOURCE_TYPE_NORMAL &&
source->finalizer) {
tpl_gsource *finalizer = source->finalizer;
if (destroy_in_thread) {
finalizer->intended_destroy = TPL_TRUE;
+ g_mutex_lock(&thread->thread_mutex);
tpl_gsource_send_message(finalizer, 1);
+ g_mutex_unlock(&thread->thread_mutex);
} else {
__gsource_remove_and_destroy(finalizer);
source->finalizer = NULL;
else
__gsource_remove_and_destroy(source);
}
-
- g_mutex_unlock(&thread->thread_mutex);
}
void
idle_cb, (gpointer)data,
NULL);
- g_mutex_lock(>hread->thread_mutex);
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 id;