[glib/wip/gsource3: 3/7] gsource: allow NULL check and prepare functions
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/gsource3: 3/7] gsource: allow NULL check and prepare functions
- Date: Mon, 14 Jan 2013 20:22:26 +0000 (UTC)
commit 0f8ba4c417a69ccfbb5e0b00b2787c6e04ae19de
Author: Ryan Lortie <desrt desrt ca>
Date: Mon Oct 29 18:26:05 2012 +0100
gsource: allow NULL check and prepare functions
Allow for NULL GSourceFuncs.check() and .prepare().
For prepare() the source will be taken not to be ready and having an
infinite timeout. For check() the source will be taken not to be ready.
https://bugzilla.gnome.org/show_bug.cgi?id=686853
glib/gmain.c | 54 ++++++++++++++++++++++++++++++++++--------------------
glib/gmain.h | 8 ++++++--
2 files changed, 40 insertions(+), 22 deletions(-)
---
diff --git a/glib/gmain.c b/glib/gmain.c
index 217eaf6..071694c 100644
--- a/glib/gmain.c
+++ b/glib/gmain.c
@@ -3045,17 +3045,26 @@ g_main_context_prepare (GMainContext *context,
if (!(source->flags & G_SOURCE_READY))
{
gboolean result;
- gboolean (*prepare) (GSource *source,
- gint *timeout);
+ gboolean (* prepare) (GSource *source,
+ gint *timeout);
- prepare = source->source_funcs->prepare;
- context->in_check_or_prepare++;
- UNLOCK_CONTEXT (context);
+ prepare = source->source_funcs->prepare;
- result = (*prepare) (source, &source_timeout);
+ if (prepare)
+ {
+ context->in_check_or_prepare++;
+ UNLOCK_CONTEXT (context);
- LOCK_CONTEXT (context);
- context->in_check_or_prepare--;
+ result = (* prepare) (source, &source_timeout);
+
+ LOCK_CONTEXT (context);
+ context->in_check_or_prepare--;
+ }
+ else
+ {
+ source_timeout = -1;
+ result = FALSE;
+ }
if (result)
{
@@ -3227,19 +3236,24 @@ g_main_context_check (GMainContext *context,
if (!(source->flags & G_SOURCE_READY))
{
- gboolean result;
- gboolean (*check) (GSource *source);
+ gboolean result;
+ gboolean (* check) (GSource *source);
+
+ check = source->source_funcs->check;
+
+ if (check)
+ {
+ context->in_check_or_prepare++;
+ UNLOCK_CONTEXT (context);
+
+ result = (* check) (source);
+
+ LOCK_CONTEXT (context);
+ context->in_check_or_prepare--;
+ }
+ else
+ result = FALSE;
- check = source->source_funcs->check;
-
- context->in_check_or_prepare++;
- UNLOCK_CONTEXT (context);
-
- result = (*check) (source);
-
- LOCK_CONTEXT (context);
- context->in_check_or_prepare--;
-
if (result)
{
GSource *ready_source = source;
diff --git a/glib/gmain.h b/glib/gmain.h
index 5a6a72a..04cf2f8 100644
--- a/glib/gmain.h
+++ b/glib/gmain.h
@@ -86,11 +86,15 @@ typedef struct _GSourceCallbackFuncs GSourceCallbackFuncs;
* a @timeout_ value which should be the maximum timeout (in milliseconds)
* which should be passed to the poll() call. The actual timeout used will
* be -1 if all sources returned -1, or it will be the minimum of all the
- * @timeout_ values returned which were >= 0.
+ * @timeout_ values returned which were >= 0. Since 2.36 this may
+ * be %NULL, in which case the effect is as if the function always
+ * returns %FALSE with a timeout of -1.
* @check: Called after all the file descriptors are polled. The source
* should return %TRUE if it is ready to be dispatched. Note that some
* time may have passed since the previous prepare function was called,
- * so the source should be checked again here.
+ * so the source should be checked again here. Since 2.36 this may
+ * be %NULL, in which case the effect is as if the function always
+ * returns %FALSE.
* @dispatch: Called to dispatch the event source, after it has returned
* %TRUE in either its @prepare or its @check function. The @dispatch
* function is passed in a callback function and data. The callback
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]