Merge lp:~mardy/libsignon-glib/context-lp1607799 into lp:libsignon-glib

Proposed by Alberto Mardegan
Status: Merged
Approved by: Marcus Tomlinson
Approved revision: 164
Merged at revision: 163
Proposed branch: lp:~mardy/libsignon-glib/context-lp1607799
Merge into: lp:libsignon-glib
Diff against target: 111 lines (+22/-32)
3 files modified
debian/changelog (+7/-0)
libsignon-glib/signon-proxy.c (+15/-9)
tests/check_signon.c (+0/-23)
To merge this branch: bzr merge lp:~mardy/libsignon-glib/context-lp1607799
Reviewer Review Type Date Requested Status
Marcus Tomlinson (community) Approve
Review via email: mp+301644@code.launchpad.net

Commit message

Lib: don't use g_idle_add, respect thread affinity

After commit 4e85baaf483268d04bbf835bebeac4ae30c7c327 libsignon-glib
stopped working when used in a thread on which
g_main_context_push_thread_default() had been called: the reason is that
g_idle_add()'s callback is always involved on the default GMainContext,
and not on the one used by the current thread.

We fix this problem by using g_source directly.

Description of the change

Lib: don't use g_idle_add, respect thread affinity

After commit 4e85baaf483268d04bbf835bebeac4ae30c7c327 libsignon-glib
stopped working when used in a thread on which
g_main_context_push_thread_default() had been called: the reason is that
g_idle_add()'s callback is always involved on the default GMainContext,
and not on the one used by the current thread.

We fix this problem by using g_source directly.

To post a comment you must log in.
164. By Alberto Mardegan

Changelog

* Merge from upstream.
  - Lib: don't use g_idle_add, respect thread affinity (LP: #1607799)

Revision history for this message
Marcus Tomlinson (marcustomlinson) wrote :

Excellent work, thanks mardy.

review: Approve
165. By Alberto Mardegan

Merge from upstream

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2016-07-18 07:43:45 +0000
3+++ debian/changelog 2016-08-02 14:09:08 +0000
4@@ -1,3 +1,10 @@
5+libsignon-glib (1.14+16.10.20160718-0ubuntu2) UNRELEASED; urgency=medium
6+
7+ * Merge from upstream.
8+ - Lib: don't use g_idle_add, respect thread affinity (LP: #1607799)
9+
10+ -- Alberto Mardegan <alberto.mardegan@canonical.com> Mon, 01 Aug 2016 16:19:55 +0300
11+
12 libsignon-glib (1.14+16.10.20160718-0ubuntu1) yakkety; urgency=medium
13
14 * Merge from upstream proposed branch
15
16=== modified file 'libsignon-glib/signon-proxy.c'
17--- libsignon-glib/signon-proxy.c 2016-06-22 07:53:40 +0000
18+++ libsignon-glib/signon-proxy.c 2016-08-02 14:09:08 +0000
19@@ -36,7 +36,7 @@
20 typedef struct {
21 gpointer self;
22 GSList *callbacks;
23- guint idle_id;
24+ GSource *idle_source;
25 } SignonReadyData;
26
27 static void
28@@ -95,10 +95,11 @@
29 GError error = { 555, 666, "Object disposed" };
30 signon_proxy_invoke_ready_callbacks (rd, &error);
31 }
32- if (rd->idle_id > 0)
33+ if (rd->idle_source)
34 {
35- g_source_remove (rd->idle_id);
36- rd->idle_id = 0;
37+ g_main_context_unref (g_source_get_context (rd->idle_source));
38+ g_source_destroy (rd->idle_source);
39+ rd->idle_source = NULL;
40 }
41 g_slice_free (SignonReadyData, rd);
42 }
43@@ -119,7 +120,8 @@
44 signon_proxy_setup (SIGNON_PROXY (rd->self));
45 }
46
47- rd->idle_id = 0;
48+ g_main_context_unref (g_source_get_context (rd->idle_source));
49+ rd->idle_source = NULL;
50 return FALSE;
51 }
52
53@@ -158,16 +160,20 @@
54 rd = g_slice_new (SignonReadyData);
55 rd->self = object;
56 rd->callbacks = NULL;
57- rd->idle_id = 0;
58+ rd->idle_source = NULL;
59 g_object_set_qdata_full ((GObject *)object, quark, rd,
60 (GDestroyNotify)signon_ready_data_free);
61 }
62
63 rd->callbacks = g_slist_append (rd->callbacks, cb);
64- if (rd->idle_id == 0)
65+ if (!rd->idle_source)
66 {
67- rd->idle_id =
68- g_idle_add ((GSourceFunc)signon_proxy_call_when_ready_idle, rd);
69+ rd->idle_source = g_idle_source_new ();
70+ g_source_set_callback (rd->idle_source,
71+ (GSourceFunc)signon_proxy_call_when_ready_idle,
72+ rd, NULL);
73+ g_source_attach (rd->idle_source,
74+ g_main_context_ref_thread_default ());
75 }
76 }
77
78
79=== modified file 'tests/check_signon.c'
80--- tests/check_signon.c 2016-06-22 07:53:40 +0000
81+++ tests/check_signon.c 2016-08-02 14:09:08 +0000
82@@ -1064,29 +1064,6 @@
83 signon_identity_remove(idty, identity_remove_cb, NULL);
84 g_main_loop_run (main_loop);
85
86- GHashTable *methods = create_methods_hashtable();
87-
88- gchar username[] = "James Bond";
89- gchar secret[] = "007";
90- gchar caption[] = "caption";
91-
92- signon_identity_store_credentials_with_args (idty,
93- username,
94- secret,
95- 1,
96- methods,
97- caption,
98- NULL,
99- NULL,
100- 0,
101- store_credentials_identity_cb,
102- NULL);
103- g_hash_table_destroy (methods);
104- g_main_loop_run (main_loop);
105-
106- signon_identity_remove(idty, identity_remove_cb, NULL);
107- g_main_loop_run (main_loop);
108-
109 /*
110 * Try to remove existing identy
111 * */

Subscribers

People subscribed via source and target branches

to all changes: