diff options
author | YoungHun Kim <yh8004.kim@samsung.com> | 2019-10-17 11:50:58 +0900 |
---|---|---|
committer | YoungHun Kim <yh8004.kim@samsung.com> | 2019-11-01 13:33:16 +0900 |
commit | 0c160eaadd8f432e0b818ea6b9ca8ae2dbaf14eb (patch) | |
tree | 7dd3e44c3f6d783896eab97c9b7d5cbc1de2ce61 | |
parent | 1b1317526197c7636f1d3817c72ad2f8d06034a5 (diff) | |
download | murphy-0c160eaadd8f432e0b818ea6b9ca8ae2dbaf14eb.tar.gz murphy-0c160eaadd8f432e0b818ea6b9ca8ae2dbaf14eb.tar.bz2 murphy-0c160eaadd8f432e0b818ea6b9ca8ae2dbaf14eb.zip |
Wait until context is owned by worker thread to avoid context owner warningsubmit/tizen_5.5_wearable_hotfix/20201026.184307submit/tizen_5.5/20191105.005038accepted/tizen/5.5/unified/wearable/hotfix/20201027.100148accepted/tizen/5.5/unified/20191107.051248tizen_5.5_wearable_hotfixtizen_5.5_tvaccepted/tizen_5.5_unified_wearable_hotfix
- We must ensure g_main_context_push_thread_default() is executed before
mm-resource-manager return mainloop when calling mrp_mainloop_glib_get()
Change-Id: I18dca7760010d882584ab9feb5aba34eb005127b
-rw-r--r-- | packaging/murphy.spec | 2 | ||||
-rw-r--r-- | src/common/glib-glue.c | 31 |
2 files changed, 28 insertions, 5 deletions
diff --git a/packaging/murphy.spec b/packaging/murphy.spec index ecf897a..6949b37 100644 --- a/packaging/murphy.spec +++ b/packaging/murphy.spec @@ -29,7 +29,7 @@ Summary: Resource policy framework Name: murphy Version: 0.0.75 -Release: 17 +Release: 18 License: BSD-3-Clause Group: System/Service URL: http://01.org/murphy/ diff --git a/src/common/glib-glue.c b/src/common/glib-glue.c index a1f7275..22816cf 100644 --- a/src/common/glib-glue.c +++ b/src/common/glib-glue.c @@ -45,6 +45,7 @@ typedef struct { GMutex glue_internal_lock; GCond loop_cond; gint ref_count; + gboolean thread_ready; } glib_glue_t; @@ -477,6 +478,7 @@ static void unregister(void *data) } g_mutex_unlock(&glue->glue_internal_lock); + g_main_context_unref(loop_ctx); glue_unref(glue); } @@ -500,12 +502,18 @@ thread_main (gpointer data) g_return_val_if_fail(glue, NULL); GMainContext *thread_main_context = g_main_loop_get_context(glue->gml); - /* Set up the thread’s context and run it. */ - g_main_context_push_thread_default (thread_main_context); + /* Set up the thread's context and run it. */ + g_main_context_push_thread_default(thread_main_context); - g_main_loop_run (glue->gml); + g_mutex_lock(&glue->glue_internal_lock); + glue->thread_ready = TRUE; + g_cond_signal(&glue->loop_cond); + g_mutex_unlock(&glue->glue_internal_lock); - g_main_context_pop_thread_default (thread_main_context); + g_main_loop_run(glue->gml); + g_main_loop_unref(glue->gml); + + g_main_context_pop_thread_default(thread_main_context); g_mutex_lock(&glue->glue_internal_lock); g_cond_signal(&glue->loop_cond); @@ -514,6 +522,16 @@ thread_main (gpointer data) return NULL; } + +static gboolean check_owner(gpointer data) +{ + if (data != NULL) + g_assert(data == g_thread_self()); + + return FALSE; +} + + int mrp_mainloop_register_with_glib(mrp_mainloop_t *ml, GMainLoop *gml) { glib_glue_t *glue; @@ -534,6 +552,11 @@ int mrp_mainloop_register_with_glib(mrp_mainloop_t *ml, GMainLoop *gml) mrp_log_error("Thread creation failed"); return FALSE; } + g_mutex_lock(&glue->glue_internal_lock); + while (!glue->thread_ready) + g_cond_wait(&glue->loop_cond, &glue->glue_internal_lock); + g_mutex_unlock(&glue->glue_internal_lock); + g_main_context_invoke(loop_ctx, check_owner, glue->worker); } return TRUE; } |