pull: Push a temporary main context for sync requests

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
This commit is contained in:
Matthew Barnes 2015-11-13 20:37:13 -05:00
parent 54066420cf
commit f0b143ca8a
2 changed files with 8 additions and 11 deletions

View 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;
}

View 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);