[gnome-builder] egg-task-cache: Set up and invoke the in-flight GTask in two steps

commit bc6c8809dcf315d2690c4e1096bbb6c0bab901d3
Author: Debarshi Ray <debarshir gnome org>
Date:   Mon Mar 6 19:13:08 2017 +0100

    egg-task-cache: Set up and invoke the in-flight GTask in two steps
    Proper cancellation handling, when multiple tasks are queued for a
    given key, requires that the caller's GCancellable::cancelled be
    monitored. Fetching of the value should be aborted once all the queued
    tasks have been cancelled.
    It will be nice to cancel the in-flight GTask even before it's invoked,
    if the first caller's GCancellable is already cancelled.
    Therefore, it will simplify the GCancellable::cancelled handler if the
    connection to it is made after the in-flight GTask has been created
    and added to the GHashTable, but before it has been invoked. This is
    meant to help with that.

 contrib/egg/egg-task-cache.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/contrib/egg/egg-task-cache.c b/contrib/egg/egg-task-cache.c
index 8d7493e..fed4985 100644
--- a/contrib/egg/egg-task-cache.c
+++ b/contrib/egg/egg-task-cache.c
@@ -466,6 +466,7 @@ egg_task_cache_get_async (EggTaskCache        *self,
                           GAsyncReadyCallback  callback,
                           gpointer             user_data)
+  g_autoptr(GTask) fetch_task = NULL;
   g_autoptr(GTask) task = NULL;
   GPtrArray *queued;
   gpointer ret;
@@ -510,8 +511,6 @@ egg_task_cache_get_async (EggTaskCache        *self,
   if (!g_hash_table_contains (self->in_flight, key))
-      g_autoptr(GTask) fetch_task = NULL;
       fetch_task = g_task_new (self,
@@ -519,6 +518,10 @@ egg_task_cache_get_async (EggTaskCache        *self,
       g_hash_table_insert (self->in_flight,
                            self->key_copy_func ((gpointer)key),
                            g_object_ref (fetch_task));
+    }
+  if (fetch_task != NULL)
+    {
       self->populate_callback (self,
                                g_object_ref (fetch_task),

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]