summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common/glib-glue.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/common/glib-glue.c b/src/common/glib-glue.c
index 21f3dfb..9bfcdf1 100644
--- a/src/common/glib-glue.c
+++ b/src/common/glib-glue.c
@@ -35,9 +35,11 @@
#include <murphy/common/mm.h>
#include <murphy/common/mainloop.h>
+#define MURPHY_LOOP_WAIT_TIME_THREAD 1
static GMutex g_murphy_glue_callback_lock;
static GMutex g_murphy_glue_internal_lock;
+static GCond g_murphy_loop_cond;
typedef struct {
@@ -385,16 +387,21 @@ static void unregister(void *data)
glib_glue_t *glue = (glib_glue_t *)data;
GMainContext *def_ctx = g_main_context_default();
GMainContext *loop_ctx = g_main_loop_get_context(glue->gml);
+ g_mutex_lock(&g_murphy_glue_internal_lock);
if (loop_ctx && def_ctx != loop_ctx) {
GSource *idle = g_idle_source_new();
+ gint64 end_time = 0;
g_source_set_callback(idle, (GSourceFunc) g_main_loop_quit,
glue->gml, NULL);
g_source_attach(idle, g_main_loop_get_context(glue->gml));
g_source_unref(idle);
- g_thread_join(glue->worker);
- glue->worker = NULL;
+ end_time = g_get_monotonic_time() + MURPHY_LOOP_WAIT_TIME_THREAD * G_TIME_SPAN_SECOND;
+ if (g_cond_wait_until(&g_murphy_loop_cond, &g_murphy_glue_internal_lock, end_time)) {
+ g_thread_join(glue->worker);
+ glue->worker = NULL;
+ }
}
if (glue->gml) {
@@ -403,6 +410,7 @@ static void unregister(void *data)
}
mrp_free(glue);
+ g_mutex_unlock(&g_murphy_glue_internal_lock);
}
@@ -431,6 +439,10 @@ thread_main (gpointer data)
g_main_context_pop_thread_default (thread_main_context);
+ g_mutex_lock(&g_murphy_glue_internal_lock);
+ g_cond_signal(&g_murphy_loop_cond);
+ g_mutex_unlock(&g_murphy_glue_internal_lock);
+
return NULL;
}
@@ -497,6 +509,7 @@ MRP_INIT static void mrp_main_loop_init_lock()
{
g_mutex_init(&g_murphy_glue_callback_lock);
g_mutex_init(&g_murphy_glue_internal_lock);
+ g_cond_init(&g_murphy_loop_cond);
}
@@ -504,4 +517,5 @@ MRP_EXIT static void mrp_main_loop_clear_lock()
{
g_mutex_clear(&g_murphy_glue_callback_lock);
g_mutex_clear(&g_murphy_glue_internal_lock);
+ g_cond_clear(&g_murphy_loop_cond);
}