]> git.pld-linux.org Git - packages/glib2.git/blob - glib2-lo_loop.patch
upstream fix 5d74233 to fix loop in libreoffice; rel 2
[packages/glib2.git] / glib2-lo_loop.patch
1 From 5d74233476d61771b4d67d50bec5420f551ef922 Mon Sep 17 00:00:00 2001
2 From: Paolo Bonzini <pbonzini@redhat.com>
3 Date: Tue, 4 Apr 2017 09:56:47 +0200
4 Subject: gmain: only signal GWakeup right before or during a blocking poll
5
6 Since commit e4ee307 ("Do not wake up main loop if change is from same
7 thread", bug 761102), GMainContext uses context->owner to decide if the
8 event loop is being run in the current thread.  However, what really
9 matters is the phase in the prepare/query/poll/check/dispatch sequence.
10 Wakeups are only needed between the end of prepare and the end of poll,
11 and then only if prepare found that no sources were ready.
12
13 There is no need to take threads into account, because prepare, check
14 and all callers of conditional_wakeup all look at the new need_wakeup
15 flag inside LOCK_CONTEXT/UNLOCK_CONTEXT.
16
17 With this change, g_main_context_is_owner and g_main_context_wait are
18 the only functions for which acquire/release matters, just like before
19 commit e4ee307.
20
21 Signed-off-by: Paolo Bonzini <bonzini@gnu.org>
22 ---
23  glib/gmain.c | 30 +++++++++++++++++++-----------
24  1 file changed, 19 insertions(+), 11 deletions(-)
25
26 diff --git a/glib/gmain.c b/glib/gmain.c
27 index ab2908e..af0a29a 100644
28 --- a/glib/gmain.c
29 +++ b/glib/gmain.c
30 @@ -277,7 +277,8 @@ struct _GMainContext
31  
32    guint next_id;
33    GList *source_lists;
34 -  gint in_check_or_prepare;
35 +  gboolean in_check_or_prepare;
36 +  gboolean need_wakeup;
37  
38    GPollRec *poll_records;
39    guint n_poll_records;
40 @@ -651,6 +652,7 @@ g_main_context_new (void)
41    
42    context->pending_dispatches = g_ptr_array_new ();
43    
44 +  context->need_wakeup = FALSE;
45    context->time_is_fresh = FALSE;
46    
47    context->wakeup = g_wakeup_new ();
48 @@ -1127,17 +1129,11 @@ source_remove_from_context (GSource      *source,
49  static void
50  conditional_wakeup (GMainContext *context)
51  {
52 -  /* We want to signal wakeups in two cases:
53 -   *  1 When the context is owned by another thread
54 -   *  2 When the context owner is NULL (two subcases)
55 -   *   2a Possible if the context has never been acquired
56 -   *   2b Or if the context has no current owner
57 -   *
58 -   * At least case 2a) is necessary to ensure backwards compatibility with
59 -   * qemu's use of GMainContext.
60 -   * https://bugzilla.gnome.org/show_bug.cgi?id=761102#c14
61 +  /* This flag is set if at the start of prepare() we have no other ready
62 +   * sources, and hence would wait in poll(). In that case, any other threads
63 +   * attaching sources will need to signal a wakeup.
64     */
65 -  if (context->owner != G_THREAD_SELF)
66 +  if (context->need_wakeup)
67      g_wakeup_signal (context->wakeup);
68  }
69  
70 @@ -3469,6 +3465,10 @@ g_main_context_prepare (GMainContext *context,
71    
72    LOCK_CONTEXT (context);
73  
74 +  /* context->need_wakeup is protected by LOCK_CONTEXT/UNLOCK_CONTEXT,
75 +   * so need not set it yet.
76 +   */
77 +
78    context->time_is_fresh = FALSE;
79  
80    if (context->in_check_or_prepare)
81 @@ -3594,6 +3594,8 @@ g_main_context_prepare (GMainContext *context,
82         }
83      }
84    g_source_iter_clear (&iter);
85 +  /* See conditional_wakeup() where this is used */
86 +  context->need_wakeup = (n_ready == 0);
87  
88    TRACE (GLIB_MAIN_CONTEXT_AFTER_PREPARE (context, current_priority, n_ready));
89  
90 @@ -3728,6 +3730,12 @@ g_main_context_check (GMainContext *context,
91  
92    TRACE (GLIB_MAIN_CONTEXT_BEFORE_CHECK (context, max_priority, fds, n_fds));
93  
94 +  /* We don't need to wakeup during check or dispatch, because
95 +   * all sources will be re-evaluated during prepare/query.
96 +   */
97 +  context->need_wakeup = FALSE;
98 +
99 +  /* And if we have a wakeup pending, acknowledge it */
100    for (i = 0; i < n_fds; i++)
101      {
102        if (fds[i].fd == context->wake_up_rec.fd)
103 -- 
104 cgit v0.12
105
This page took 0.076727 seconds and 3 git commands to generate.