[connection] Modified logic so that callback is sent to their respective thread 14/56314/1
authorSaurav Babu <saurav.babu@samsung.com>
Wed, 6 Jan 2016 09:26:19 +0000 (14:56 +0530)
committerSaurav Babu <saurav.babu@samsung.com>
Wed, 6 Jan 2016 09:34:01 +0000 (15:04 +0530)
Currently for sending few callbacks to application g_idle_add_full() is
used. g_idle_add_full() adds the callback in global main context of the
application and not the context in which thread was operating. See
description at https://developer.gnome.org/glib/stable/glib-The-Main-Event-Loop.html#g-idle-add-full
This patch modifies the logic to create a g_idle_source_new() and then
attach this source to the thread's context rather than global main
context of application.

Change-Id: I5b9b927760ab2281cfd3878a3c7583bc4a00e74f
Signed-off-by: Saurav Babu <saurav.babu@samsung.com>
src/libnetwork.c

index 8f30b58..46df5f7 100755 (executable)
@@ -1444,6 +1444,8 @@ guint _connection_callback_add(GSourceFunc func, gpointer user_data)
 {
        guint id;
        struct managed_idle_data *data;
+       GMainContext *context;
+       GSource *src;
 
        if (!func)
                return 0;
@@ -1455,8 +1457,12 @@ guint _connection_callback_add(GSourceFunc func, gpointer user_data)
        data->func = func;
        data->user_data = user_data;
 
-       id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, __connection_idle_cb, data,
-                       __connection_idle_destroy_cb);
+       context = g_main_context_get_thread_default();
+       src = g_idle_source_new();
+       g_source_set_callback(src, __connection_idle_cb, data,
+               __connection_idle_destroy_cb);
+       id = g_source_attach(src, context);
+       g_source_unref(src);
        if (!id) {
                g_free(data);
                return id;