fetcher: Hold a ref to main context for lifetime of thread
I don't think this fixes the bug I was seeing, but it makes me more comfortable to know we have a strong ref to the main context across the thread lifetime, and we only unset the default right before we go away. If something in `thread_closure_unref()` used `g_main_context_get_thread_default()` for example it'd be wrong before. Closes: #383 Approved by: mbarnes
This commit is contained in:
parent
d7629d33a4
commit
b4c15209e8
|
|
@ -452,12 +452,13 @@ static gpointer
|
||||||
ostree_fetcher_session_thread (gpointer data)
|
ostree_fetcher_session_thread (gpointer data)
|
||||||
{
|
{
|
||||||
ThreadClosure *closure = data;
|
ThreadClosure *closure = data;
|
||||||
|
g_autoptr(GMainContext) mainctx = g_main_context_ref (closure->main_context);
|
||||||
gint max_conns;
|
gint max_conns;
|
||||||
|
|
||||||
/* This becomes the GMainContext that SoupSession schedules async
|
/* This becomes the GMainContext that SoupSession schedules async
|
||||||
* callbacks and emits signals from. Make it the thread-default
|
* callbacks and emits signals from. Make it the thread-default
|
||||||
* context for this thread before creating the session. */
|
* context for this thread before creating the session. */
|
||||||
g_main_context_push_thread_default (closure->main_context);
|
g_main_context_push_thread_default (mainctx);
|
||||||
|
|
||||||
closure->session = soup_session_async_new_with_options (SOUP_SESSION_USER_AGENT, "ostree ",
|
closure->session = soup_session_async_new_with_options (SOUP_SESSION_USER_AGENT, "ostree ",
|
||||||
SOUP_SESSION_SSL_USE_SYSTEM_CA_FILE, TRUE,
|
SOUP_SESSION_SSL_USE_SYSTEM_CA_FILE, TRUE,
|
||||||
|
|
@ -481,10 +482,13 @@ ostree_fetcher_session_thread (gpointer data)
|
||||||
|
|
||||||
g_main_loop_run (closure->main_loop);
|
g_main_loop_run (closure->main_loop);
|
||||||
|
|
||||||
g_main_context_pop_thread_default (closure->main_context);
|
|
||||||
|
|
||||||
thread_closure_unref (closure);
|
thread_closure_unref (closure);
|
||||||
|
|
||||||
|
/* Do this last, since libsoup uses g_main_current_source() which
|
||||||
|
* relies on it.
|
||||||
|
*/
|
||||||
|
g_main_context_pop_thread_default (mainctx);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue