diff options
author | Volodymyr Brynza <v.brynza@samsung.com> | 2017-05-12 11:46:24 +0300 |
---|---|---|
committer | Volodymyr Brynza <v.brynza@samsung.com> | 2017-05-12 11:46:24 +0300 |
commit | e990698aa7a6ba49a3c4893207d2c87c9107f99e (patch) | |
tree | b585ae4f1f97ce8555438358c61a2a3df79851fa | |
parent | 7530223154d5afb8d54ea7ed4b4e65257e6d46a6 (diff) | |
download | murphy-e990698aa7a6ba49a3c4893207d2c87c9107f99e.tar.gz murphy-e990698aa7a6ba49a3c4893207d2c87c9107f99e.tar.bz2 murphy-e990698aa7a6ba49a3c4893207d2c87c9107f99e.zip |
Add timed wait to thread loop join to avoid timeouts
Change-Id: Iae53916efcbd3591f7e3b94bf8551fc29ead7b96
Signed-off-by: Volodymyr Brynza <v.brynza@samsung.com>
-rw-r--r-- | src/common/glib-glue.c | 18 |
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); } |