[glib/wip/rishi/gtask-return-cancelled] gtask: Ensure that cancelled tasks are returned asynchronously



commit 16dffc6eaf0b0b17c3b00340834db4cb1a32ca37
Author: Debarshi Ray <debarshir gnome org>
Date:   Mon Dec 3 20:10:41 2018 +0100

    gtask: Ensure that cancelled tasks are returned asynchronously
    
    Spotted by Dan Winship and Michael Catanzaro.
    
    https://gitlab.gnome.org/GNOME/glib/issues/1608

 gio/gtask.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
---
diff --git a/gio/gtask.c b/gio/gtask.c
index a40bc01b4..2784b8253 100644
--- a/gio/gtask.c
+++ b/gio/gtask.c
@@ -1210,9 +1210,18 @@ g_task_return (GTask           *task,
        */
       if (g_source_get_time (source) > task->creation_time)
         {
-          g_task_return_now (task);
-          g_object_unref (task);
-          return;
+          /* Finally, if the task has been cancelled, we shouldn't
+           * return synchronously from inside the
+           * GCancellable::cancelled handler. It's easier to run
+           * another iteration of the main loop than tracking how the
+           * cancellation was handled.
+           */
+          if (!g_cancellable_is_cancelled (task->cancellable))
+            {
+              g_task_return_now (task);
+              g_object_unref (task);
+              return;
+            }
         }
     }
 


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