Merge lp:~attente/unity-gtk-module/1258669 into lp:unity-gtk-module/14.04

Proposed by William Hua
Status: Merged
Approved by: Charles Kerr
Approved revision: 317
Merged at revision: 316
Proposed branch: lp:~attente/unity-gtk-module/1258669
Merge into: lp:unity-gtk-module/14.04
Diff against target: 45 lines (+28/-1)
1 file modified
lib/unity-gtk-menu-shell.c (+28/-1)
To merge this branch: bzr merge lp:~attente/unity-gtk-module/1258669
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+209132@code.launchpad.net

Commit message

Dispatch gtk_menu_item_activate () in a GDK idle.

Description of the change

Dispatch gtk_menu_item_activate () in a GDK idle.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

Probably would be best to add a comment to this describing why the activation has to be deferred to an idle timeout? I'm not saying this doesn't solve the bug, but it's not clear to me why it does... :)

review: Needs Information
lp:~attente/unity-gtk-module/1258669 updated
316. By William Hua

Describe why the deadlock occurs.

Revision history for this message
William Hua (attente) wrote :

Thanks Charles, to be honest, it's not clear to me what the culprit is. But I've added a comment with as much information as I know, with Ryan's help on the speculation. Hopefully someone smarter comes along and can tell us why exactly it happens...

It definitely does fix the problem though :)

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
lp:~attente/unity-gtk-module/1258669 updated
317. By William Hua

Merge trunk.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

Thanks Will :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/unity-gtk-menu-shell.c'
2--- lib/unity-gtk-menu-shell.c 2014-03-05 17:17:35 +0000
3+++ lib/unity-gtk-menu-shell.c 2014-03-06 18:56:31 +0000
4@@ -93,6 +93,16 @@
5 return !g_sequence_iter_is_end (iter) && g_sequence_get_uint (iter) <= i ? iter : NULL;
6 }
7
8+static gboolean
9+gtk_menu_item_handle_idle_activate (gpointer user_data)
10+{
11+ g_return_val_if_fail (GTK_IS_MENU_ITEM (user_data), G_SOURCE_REMOVE);
12+
13+ gtk_menu_item_activate (user_data);
14+
15+ return G_SOURCE_REMOVE;
16+}
17+
18 static GPtrArray *
19 unity_gtk_menu_shell_get_items (UnityGtkMenuShell *shell)
20 {
21@@ -1027,7 +1037,24 @@
22 if (GTK_IS_MENU (shell->menu_shell))
23 gtk_menu_set_active (GTK_MENU (shell->menu_shell), item->item_index);
24
25- gtk_menu_item_activate (item->menu_item);
26+ /*
27+ * We dispatch the menu item activation in an idle to fix LP: #1258669.
28+ *
29+ * We get a deadlock when the menu item is activated if something like
30+ * gtk_dialog_run () is called. gtk_dialog_run () releases the GDK lock
31+ * just before starting its own main loop, and tries to re-acquire it
32+ * once it terminates. For whatever reason, a direct call to
33+ * gtk_menu_item_activate () here causes the GDK lock to be acquired
34+ * before gtk_dialog_run () tries to acquire it, whereas dispatching it
35+ * using gdk_threads_add_idle_full () seems to cleanly acquire the lock
36+ * once only at the beginning, preventing the deadlock.
37+ *
38+ * Suspicion is that this was executing during the main context
39+ * iteration of gtk_main_iteration (), which grabs the GDK lock
40+ * immediately after. But it's still not clear how that's possible....
41+ */
42+
43+ gdk_threads_add_idle_full (G_PRIORITY_DEFAULT_IDLE, gtk_menu_item_handle_idle_activate, g_object_ref (item->menu_item), g_object_unref);
44 }
45 }
46

Subscribers

People subscribed via source and target branches