pull: Push a temporary main context for sync requests
authorMatthew Barnes <mbarnes@redhat.com>
Sat, 14 Nov 2015 01:37:13 +0000 (20:37 -0500)
committerMatthew Barnes <mbarnes@redhat.com>
Mon, 14 Dec 2015 16:11:34 +0000 (11:11 -0500)
Given the previous commit, which isolates SoupSession in a separate
thread, it should be safe to start pushing a temporary main context
for synchronous requests again.

This partially reverts 84fe2ff, which partially reverted 9f3d586.

Related to https://bugzilla.gnome.org/show_bug.cgi?id=753336

src/libostree/ostree-fetcher.c
src/libostree/ostree-metalink.c

index 2964a1aafcac97088648f8d014270dfc7184f315..8f103080e3279554fb85c00d10ab5babf62c136a 100644 (file)
@@ -1083,10 +1083,6 @@ fetch_uri_sync_on_complete (GObject        *object,
   data->done = TRUE;
 }
 
-/* Synchronously request a URI - will iterate the thread-default main
- * context for historical reasons.  If you don't want that, push a
- * temporary one.
- */
 gboolean
 _ostree_fetcher_request_uri_to_membuf (OstreeFetcher  *fetcher,
                                        SoupURI        *uri,
@@ -1110,7 +1106,8 @@ _ostree_fetcher_request_uri_to_membuf (OstreeFetcher  *fetcher,
   if (g_cancellable_set_error_if_cancelled (cancellable, error))
     return FALSE;
 
-  mainctx = g_main_context_ref_thread_default ();
+  mainctx = g_main_context_new ();
+  g_main_context_push_thread_default (mainctx);
 
   data.done = FALSE;
   data.error = error;
@@ -1155,6 +1152,8 @@ _ostree_fetcher_request_uri_to_membuf (OstreeFetcher  *fetcher,
   ret = TRUE;
   *out_contents = g_memory_output_stream_steal_as_bytes (buf);
  out:
+  if (mainctx)
+    g_main_context_pop_thread_default (mainctx);
   g_clear_object (&(data.result_stream));
   return ret;
 }
index 083ad16fb2dd33be533df5eeae16626290b1b03c..5ca69e6980ff994ad5ab6e11d31f93cc285ce889 100644 (file)
@@ -589,11 +589,6 @@ typedef struct
   GMainLoop             *loop;
 } FetchMetalinkSyncData;
 
-/*
- * Note that for legacy reasons we iterate the caller's main context.
- * If you don't want that (and you probably don't) push a temporary
- * one.
- */
 gboolean
 _ostree_metalink_request_sync (OstreeMetalink        *self,
                                SoupURI               **out_target_uri,
@@ -612,7 +607,8 @@ _ostree_metalink_request_sync (OstreeMetalink        *self,
   if (fetching_sync_uri != NULL)
     *fetching_sync_uri = _ostree_metalink_get_uri (self);
 
-  mainctx = g_main_context_ref_thread_default ();
+  mainctx = g_main_context_new ();
+  g_main_context_push_thread_default (mainctx);
 
   request.metalink = g_object_ref (self);
   request.urls = g_ptr_array_new_with_free_func ((GDestroyNotify) soup_uri_free);
@@ -637,6 +633,8 @@ _ostree_metalink_request_sync (OstreeMetalink        *self,
 
   ret = TRUE;
  out:
+  if (mainctx)
+    g_main_context_pop_thread_default (mainctx);
   g_clear_object (&request.metalink);
   g_clear_pointer (&request.urls, g_ptr_array_unref);
   g_clear_pointer (&request.parser, g_markup_parse_context_free);