[glib] GSimpleAsyncResult: push thread context around callback



commit df45856bba14b93fedcb876fe04e0bbf0d159909
Author: Dan Winship <danw gnome org>
Date:   Wed Apr 20 11:41:47 2011 -0400

    GSimpleAsyncResult: push thread context around callback
    
    When an old pre-thread-default-context API that takes an explicit
    GMainContext wants to call a gio API, it must call
    g_main_context_push_thread_default() before, and
    g_main_context_pop_thread_default() after the gio call, so that the
    gio method will return its result to the desired GMainContext.
    
    But this fails for methods like g_socket_client_connect_async() that
    make a chain of multiple async calls, since the pushed/popped context
    will only affect the initial call.
    
    Fix this by having GSimpleAsyncResult itself push/pop the context
    around the callback invocation, so that if the callback queues another
    async request, it will stay in the same context as the original one.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=646957

 gio/gsimpleasyncresult.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)
---
diff --git a/gio/gsimpleasyncresult.c b/gio/gsimpleasyncresult.c
index b58b2e5..4fd5da7 100644
--- a/gio/gsimpleasyncresult.c
+++ b/gio/gsimpleasyncresult.c
@@ -744,9 +744,13 @@ g_simple_async_result_complete (GSimpleAsyncResult *simple)
 #endif
 
   if (simple->callback)
-    simple->callback (simple->source_object,
-		      G_ASYNC_RESULT (simple),
-		      simple->user_data);
+    {
+      g_main_context_push_thread_default (simple->context);
+      simple->callback (simple->source_object,
+			G_ASYNC_RESULT (simple),
+			simple->user_data);
+      g_main_context_pop_thread_default (simple->context);
+    }
 }
 
 static gboolean



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