summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2017-03-31 16:19:58 -0400
committerColin Walters <walters@verbum.org>2017-04-11 11:56:07 -0400
commit1d38e6cf6f5b19f90480b70d92c6200d3a830dc9 (patch)
tree21c7ee413dbee5908e5cf569695747fa8731f687
parent8ef5eae6941c939eb4f7b78941d04162bf3ca872 (diff)
downloadglib-1d38e6cf6f5b19f90480b70d92c6200d3a830dc9.tar.gz
main: Create a helper function for "owner wakeup" optimization
The original patch really should have introduced a helper - among other things it deserves a code comment. We're likely to make further changes too, so it's obviously better to only do it in one place. See: https://bugzilla.gnome.org/show_bug.cgi?id=761102
-rw-r--r--glib/gmain.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/glib/gmain.c b/glib/gmain.c
index a503431a0..4f22ac501 100644
--- a/glib/gmain.c
+++ b/glib/gmain.c
@@ -1118,6 +1118,19 @@ source_remove_from_context (GSource *source,
}
}
+/* See https://bugzilla.gnome.org/show_bug.cgi?id=761102 for
+ * the introduction of this.
+ *
+ * The main optimization is to avoid waking up the main
+ * context if a change is made by the current owner.
+ */
+static void
+conditional_wakeup (GMainContext *context)
+{
+ if (context->owner && context->owner != G_THREAD_SELF)
+ g_wakeup_signal (context->wakeup);
+}
+
static guint
g_source_attach_unlocked (GSource *source,
GMainContext *context,
@@ -1164,8 +1177,8 @@ g_source_attach_unlocked (GSource *source,
/* If another thread has acquired the context, wake it up since it
* might be in poll() right now.
*/
- if (do_wakeup && context->owner && context->owner != G_THREAD_SELF)
- g_wakeup_signal (context->wakeup);
+ if (do_wakeup)
+ conditional_wakeup (context);
return source->source_id;
}
@@ -1842,8 +1855,7 @@ g_source_set_ready_time (GSource *source,
{
/* Quite likely that we need to change the timeout on the poll */
if (!SOURCE_BLOCKED (source))
- if (context->owner && context->owner != G_THREAD_SELF)
- g_wakeup_signal (context->wakeup);
+ conditional_wakeup (context);
UNLOCK_CONTEXT (context);
}
}
@@ -4361,8 +4373,7 @@ g_main_context_add_poll_unlocked (GMainContext *context,
context->poll_changed = TRUE;
/* Now wake up the main loop if it is waiting in the poll() */
- if (context->owner && context->owner != G_THREAD_SELF)
- g_wakeup_signal (context->wakeup);
+ conditional_wakeup (context);
}
/**
@@ -4420,10 +4431,9 @@ g_main_context_remove_poll_unlocked (GMainContext *context,
}
context->poll_changed = TRUE;
-
+
/* Now wake up the main loop if it is waiting in the poll() */
- if (context->owner && context->owner != G_THREAD_SELF)
- g_wakeup_signal (context->wakeup);
+ conditional_wakeup (context);
}
/**