Move Murphy client loop to new context 49/94849/3
authorVolodymyr Brynza <v.brynza@samsung.com>
Mon, 7 Nov 2016 07:34:19 +0000 (09:34 +0200)
committerVolodymyr Brynza <v.brynza@samsung.com>
Mon, 7 Nov 2016 07:34:19 +0000 (09:34 +0200)
Change-Id: If001b418679e477f59127d652f8cbb468414a357
Signed-off-by: Volodymyr Brynza <v.brynza@samsung.com>
src/include/mm_player_resource.h
src/mm_player_resource.c

index 085a65f..88d383a 100644 (file)
@@ -64,6 +64,8 @@ typedef struct {
        bool by_rm_cb;
        GCond cond;
        GMutex lock;
+       GThread *starter;
+       GMainLoop *mrp_loop;
 } MMPlayerResourceManager;
 
 int _mmplayer_resource_manager_init(MMPlayerResourceManager *resource_manager, void *user_data);
index 3c84ca5..7c7e879 100644 (file)
@@ -294,12 +294,25 @@ static int set_resource_release_cb(MMPlayerResourceManager *resource_manager)
        return ret;
 }
 
+static gpointer __mmplayer_launch_glib_murphy_loop(void *user_data)
+{
+       LOGI("Run mrp_loop");
+       MMPlayerResourceManager *resource_manager= (MMPlayerResourceManager *)user_data;
+       g_main_loop_run(resource_manager->mrp_loop);
+       LOGI("Murphy glib loop exit");
+       return NULL;
+}
+
 int _mmplayer_resource_manager_init(MMPlayerResourceManager *resource_manager, void *user_data)
 {
        MMPLAYER_FENTER();
        MMPLAYER_CHECK_RESOURCE_MANAGER_INSTANCE(resource_manager);
 
-       resource_manager->mloop = mrp_mainloop_glib_get(g_main_loop_new(NULL, TRUE));
+       GMainContext *mrp_ctx = g_main_context_new();
+       resource_manager->mrp_loop = g_main_loop_new(mrp_ctx, TRUE);
+       resource_manager->mloop = mrp_mainloop_glib_get(resource_manager->mrp_loop);
+       resource_manager->starter = g_thread_new(NULL, (GThreadFunc)__mmplayer_launch_glib_murphy_loop, resource_manager);
+       g_main_context_unref(mrp_ctx);
        if (resource_manager->mloop) {
                resource_manager->context = mrp_res_create(resource_manager->mloop, mrp_state_callback, user_data);
                if (resource_manager->context == NULL) {
@@ -475,6 +488,12 @@ int _mmplayer_resource_manager_deinit(MMPlayerResourceManager *resource_manager)
                mrp_res_destroy(resource_manager->context);
                resource_manager->context = NULL;
        }
+       if (resource_manager->mrp_loop) {
+               g_main_loop_quit(resource_manager->mrp_loop);
+               resource_manager->mrp_loop = NULL;
+       }
+       g_thread_join(resource_manager->starter);
+
        if (resource_manager->mloop) {
                mrp_mainloop_destroy(resource_manager->mloop);
                resource_manager->mloop = NULL;