[glib/wip/new-gsource-round2: 3/7] gsource: allow NULL check and prepare functions



commit c5271d13b4cee630b8be4b7b31f90b0ef7f56e35
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 133b0f1..486de35 100644
--- a/glib/gmain.c
+++ b/glib/gmain.c
@@ -2976,17 +2976,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)
 	    {
@@ -3158,19 +3167,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 de035ca..a40cb93 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]