gboolean goa_http_client_check_sync (GoaHttpClient *self, const gchar *uri, const gchar *username, const gchar *password, gboolean accept_ssl_errors, GCancellable *cancellable, GError **error) { CheckSyncData data; GMainContext *context = NULL; data.error = error; context = g_main_context_new (); g_main_context_push_thread_default (context); data.loop = g_main_loop_new (context, FALSE); goa_http_client_check (self, uri, username, password, accept_ssl_errors, cancellable, http_client_check_sync_cb, &data); g_main_loop_run (data.loop); g_main_loop_unref (data.loop); g_main_context_pop_thread_default (context); g_main_context_unref (context); return data.op_res; }
static void complete_resolve_async (SoupAddressResolveAsyncData *res_data, guint status) { GSource *current_source; GMainContext *current_context; if (res_data->callback) { /* Awful hack; to make soup_socket_connect_async() * with an non-default async_context work correctly, * we need to ensure that the non-default context * (which we're now running in) is the thread-default * when the callbacks are run... */ current_source = g_main_current_source (); if (current_source && !g_source_is_destroyed (current_source)) current_context = g_source_get_context (current_source); else current_context = NULL; g_main_context_push_thread_default (current_context); res_data->callback (res_data->addr, status, res_data->callback_data); g_main_context_pop_thread_default (current_context); } g_object_unref (res_data->addr); g_slice_free (SoupAddressResolveAsyncData, res_data); }
static void gst_gl_window_default_run (GstGLWindow * window) { GstGLWindowPrivate *priv = window->priv; if (g_main_context_get_thread_default ()) { if (priv->main_context) g_main_context_unref (priv->main_context); if (priv->loop) g_main_loop_unref (priv->loop); priv->main_context = g_main_context_ref_thread_default (); priv->loop = NULL; priv->alive = TRUE; } else { g_main_context_push_thread_default (priv->main_context); } g_main_loop_run (priv->loop); if (!priv->loop) { priv->alive = FALSE; g_main_context_unref (priv->main_context); priv->main_context = NULL; } else { g_main_context_pop_thread_default (priv->main_context); } }
static void *iothread_run(void *opaque) { IOThread *iothread = opaque; rcu_register_thread(); my_iothread = iothread; qemu_mutex_lock(&iothread->init_done_lock); iothread->thread_id = qemu_get_thread_id(); qemu_cond_signal(&iothread->init_done_cond); qemu_mutex_unlock(&iothread->init_done_lock); while (iothread->running) { aio_poll(iothread->ctx, true); if (atomic_read(&iothread->worker_context)) { GMainLoop *loop; g_main_context_push_thread_default(iothread->worker_context); iothread->main_loop = g_main_loop_new(iothread->worker_context, TRUE); loop = iothread->main_loop; g_main_loop_run(iothread->main_loop); iothread->main_loop = NULL; g_main_loop_unref(loop); g_main_context_pop_thread_default(iothread->worker_context); } } rcu_unregister_thread(); return NULL; }
PassRefPtr<AudioBus> AudioFileReader::createBus(float sampleRate, bool mixToMono) { m_sampleRate = sampleRate; m_frontLeftBuffers = gst_buffer_list_new(); m_frontRightBuffers = gst_buffer_list_new(); GRefPtr<GMainContext> context = adoptGRef(g_main_context_new()); g_main_context_push_thread_default(context.get()); m_loop = adoptGRef(g_main_loop_new(context.get(), FALSE)); // Start the pipeline processing just after the loop is started. GRefPtr<GSource> timeoutSource = adoptGRef(g_timeout_source_new(0)); g_source_attach(timeoutSource.get(), context.get()); g_source_set_callback(timeoutSource.get(), reinterpret_cast<GSourceFunc>(enteredMainLoopCallback), this, 0); g_main_loop_run(m_loop.get()); g_main_context_pop_thread_default(context.get()); if (m_errorOccurred) return 0; unsigned channels = mixToMono ? 1 : 2; RefPtr<AudioBus> audioBus = AudioBus::create(channels, m_channelSize, true); audioBus->setSampleRate(m_sampleRate); copyGstreamerBuffersToAudioChannel(m_frontLeftBuffers, audioBus->channel(0)); if (!mixToMono) copyGstreamerBuffersToAudioChannel(m_frontRightBuffers, audioBus->channel(1)); return audioBus; }
static void *janus_source_rtsp_server_thread(void *data) { if (g_atomic_int_get(&stopping) || !g_atomic_int_get(&initialized)) { JANUS_LOG(LOG_INFO, "Plugin is stopping\n"); return FALSE; } /*Create rtsp server and async queue*/ rtsp_server_data = g_malloc0(sizeof(janus_source_rtsp_server_data)); janus_source_create_rtsp_server_and_queue(rtsp_server_data, g_main_context_get_thread_default()); #ifdef USE_THREAD_CONTEXT /* Set up a worker context and make it thread-default */ GMainContext *worker_context = g_main_context_new(); g_main_context_push_thread_default(worker_context); #endif /* Create new queue source */ janus_source_attach_rtsp_queue_callback(rtsp_server_data, queue_events_callback, g_main_context_get_thread_default()); /* make a mainloop for the thread-default context */ janus_source_rtsp_create_and_run_main_loop(rtsp_server_data,g_main_context_get_thread_default()); janus_source_close_all_rtsp_sessions(rtsp_server_data); #ifdef USE_THREAD_CONTEXT g_main_context_pop_thread_default(worker_context); g_main_context_unref(worker_context); #endif return NULL; }
/** * soup_address_resolve_async: * @addr: a #SoupAddress * @async_context: (allow-none): the #GMainContext to call @callback from * @cancellable: a #GCancellable object, or %NULL * @callback: (scope async): callback to call with the result * @user_data: data for @callback * * Asynchronously resolves the missing half of @addr (its IP address * if it was created with soup_address_new(), or its hostname if it * was created with soup_address_new_from_sockaddr() or * soup_address_new_any().) * * If @cancellable is non-%NULL, it can be used to cancel the * resolution. @callback will still be invoked in this case, with a * status of %SOUP_STATUS_CANCELLED. * * It is safe to call this more than once on a given address, from the * same thread, with the same @async_context (and doing so will not * result in redundant DNS queries being made). But it is not safe to * call from multiple threads, or with different @async_contexts, or * mixed with calls to soup_address_resolve_sync(). **/ void soup_address_resolve_async (SoupAddress *addr, GMainContext *async_context, GCancellable *cancellable, SoupAddressCallback callback, gpointer user_data) { SoupAddressPrivate *priv; SoupAddressResolveAsyncData *res_data; GResolver *resolver; gboolean already_started; g_return_if_fail (SOUP_IS_ADDRESS (addr)); priv = SOUP_ADDRESS_GET_PRIVATE (addr); g_return_if_fail (priv->name || priv->sockaddr); /* We don't need to do locking here because the async case is * not intended to be thread-safe. */ if (priv->name && priv->sockaddr && !callback) return; res_data = g_slice_new0 (SoupAddressResolveAsyncData); res_data->callback = callback; res_data->callback_data = user_data; already_started = priv->async_lookups != NULL; priv->async_lookups = g_slist_prepend (priv->async_lookups, res_data); if (already_started) return; g_object_ref (addr); if (priv->name && priv->sockaddr) { soup_add_completion (async_context, idle_complete_resolve, addr); return; } resolver = g_resolver_get_default (); if (async_context) g_main_context_push_thread_default (async_context); if (priv->name) { g_resolver_lookup_by_name_async (resolver, priv->name, cancellable, lookup_resolved, addr); } else { GInetAddress *gia; gia = soup_address_make_inet_address (addr); g_resolver_lookup_by_address_async (resolver, gia, cancellable, lookup_resolved, addr); g_object_unref (gia); } if (async_context) g_main_context_pop_thread_default (async_context); g_object_unref (resolver); }
/* Main method for the native code. This is executed on its own thread. */ static void *app_function (void *userdata) { JavaVMAttachArgs args; GstBus *bus; CustomData *data = (CustomData *)userdata; GSource *bus_source; GError *error = NULL; GST_DEBUG ("Creating pipeline in CustomData at %p", data); /* Create our own GLib Main Context and make it the default one */ data->context = g_main_context_new (); g_main_context_push_thread_default(data->context); /* Build pipeline */ data->pipeline = gst_parse_launch("videotestsrc ! warptv ! videoconvert ! autovideosink", &error); if (error) { gchar *message = g_strdup_printf("Unable to build pipeline: %s", error->message); g_clear_error (&error); set_ui_message(message, data); g_free (message); return NULL; } /* Set the pipeline to READY, so it can already accept a window handle, if we have one */ gst_element_set_state(data->pipeline, GST_STATE_READY); data->video_sink = gst_bin_get_by_interface(GST_BIN(data->pipeline), GST_TYPE_VIDEO_OVERLAY); if (!data->video_sink) { GST_ERROR ("Could not retrieve video sink"); return NULL; } /* Instruct the bus to emit signals for each received message, and connect to the interesting signals */ bus = gst_element_get_bus (data->pipeline); bus_source = gst_bus_create_watch (bus); g_source_set_callback (bus_source, (GSourceFunc) gst_bus_async_signal_func, NULL, NULL); g_source_attach (bus_source, data->context); g_source_unref (bus_source); g_signal_connect (G_OBJECT (bus), "message::error", (GCallback)error_cb, data); g_signal_connect (G_OBJECT (bus), "message::state-changed", (GCallback)state_changed_cb, data); gst_object_unref (bus); /* Create a GLib Main Loop and set it to run */ GST_DEBUG ("Entering main loop... (CustomData:%p)", data); data->main_loop = g_main_loop_new (data->context, FALSE); check_initialization_complete (data); g_main_loop_run (data->main_loop); GST_DEBUG ("Exited main loop"); g_main_loop_unref (data->main_loop); data->main_loop = NULL; /* Free resources */ g_main_context_pop_thread_default(data->context); g_main_context_unref (data->context); gst_element_set_state (data->pipeline, GST_STATE_NULL); gst_object_unref (data->video_sink); gst_object_unref (data->pipeline); return NULL; }
/** * secret_prompt_perform_sync: * @self: a prompt * @window_id: XWindow id for parent window to be transient for * @cancellable: optional cancellation object * @return_type: the variant type of the prompt result * @error: location to place an error on failure * * Runs a prompt and performs the prompting. Returns a variant result if the * prompt was completed and not dismissed. The type of result depends on the * action the prompt is completing, and is defined in the Secret Service DBus * API specification. * * If @window_id is non-zero then it is used as an XWindow id. The Secret * Service can make its prompt transient for the window with this id. In some * Secret Service implementations this is not possible, so the behavior * depending on this should degrade gracefully. * * This method may block indefinitely and should not be used in user interface * threads. * * Returns: (transfer full): %NULL if the prompt was dismissed or an error occurred */ GVariant * secret_prompt_perform_sync (SecretPrompt *self, gulong window_id, GCancellable *cancellable, const GVariantType *return_type, GError **error) { GMainContext *context; GVariant *retval; g_return_val_if_fail (SECRET_IS_PROMPT (self), NULL); g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); context = g_main_context_new (); g_main_context_push_thread_default (context); retval = secret_prompt_run (self, window_id, cancellable, return_type, error); /* Needed to prevent memory leaks */ while (g_main_context_iteration (context, FALSE)); g_main_context_pop_thread_default (context); g_main_context_unref (context); return retval; }
static void watch_smartcards (GTask *task, GsdSmartcardManager *self, gpointer data, GCancellable *cancellable) { GMainContext *context; GMainLoop *loop; g_debug ("Getting list of suitable drivers"); context = g_main_context_new (); g_main_context_push_thread_default (context); activate_all_drivers_async (self, cancellable, (GAsyncReadyCallback) on_all_drivers_activated, task); loop = g_main_loop_new (context, FALSE); g_main_loop_run (loop); g_main_loop_unref (loop); g_main_context_pop_thread_default (context); g_main_context_unref (context); }
/** * gs_plugin_loader_filename_to_app: **/ GsApp * gs_plugin_loader_filename_to_app (GsPluginLoader *plugin_loader, const gchar *filename, GsPluginRefineFlags flags, GCancellable *cancellable, GError **error) { GsPluginLoaderHelper helper; /* create temp object */ helper.app = NULL; helper.context = g_main_context_new (); helper.loop = g_main_loop_new (helper.context, FALSE); helper.error = error; g_main_context_push_thread_default (helper.context); /* run async method */ gs_plugin_loader_filename_to_app_async (plugin_loader, filename, flags, cancellable, gs_plugin_loader_filename_to_app_finish_sync, &helper); g_main_loop_run (helper.loop); g_main_context_pop_thread_default (helper.context); g_main_loop_unref (helper.loop); g_main_context_unref (helper.context); return helper.app; }
/** * gs_plugin_loader_get_installed: **/ GList * gs_plugin_loader_get_installed (GsPluginLoader *plugin_loader, GsPluginRefineFlags flags, GCancellable *cancellable, GError **error) { GsPluginLoaderHelper helper; /* create temp object */ helper.context = g_main_context_new (); helper.loop = g_main_loop_new (helper.context, FALSE); helper.error = error; g_main_context_push_thread_default (helper.context); /* run async method */ gs_plugin_loader_get_installed_async (plugin_loader, flags, cancellable, (GAsyncReadyCallback) gs_plugin_loader_get_installed_finish_sync, &helper); g_main_loop_run (helper.loop); g_main_context_pop_thread_default (helper.context); g_main_loop_unref (helper.loop); g_main_context_unref (helper.context); return helper.list; }
/** * gs_plugin_loader_app_action: **/ gboolean gs_plugin_loader_app_action (GsPluginLoader *plugin_loader, GsApp *app, GsPluginLoaderAction action, GCancellable *cancellable, GError **error) { GsPluginLoaderHelper helper; /* create temp object */ helper.context = g_main_context_new (); helper.loop = g_main_loop_new (helper.context, FALSE); helper.error = error; g_main_context_push_thread_default (helper.context); /* run async method */ gs_plugin_loader_app_action_async (plugin_loader, app, action, cancellable, (GAsyncReadyCallback) gs_plugin_loader_app_action_finish_sync, &helper); g_main_loop_run (helper.loop); g_main_context_pop_thread_default (helper.context); g_main_loop_unref (helper.loop); g_main_context_unref (helper.context); return helper.ret; }
/** * gs_plugin_loader_refresh: **/ gboolean gs_plugin_loader_refresh (GsPluginLoader *plugin_loader, guint cache_age, GsPluginRefreshFlags flags, GCancellable *cancellable, GError **error) { GsPluginLoaderHelper helper; /* create temp object */ helper.context = g_main_context_new (); helper.loop = g_main_loop_new (helper.context, FALSE); helper.error = error; g_main_context_push_thread_default (helper.context); /* run async method */ gs_plugin_loader_refresh_async (plugin_loader, cache_age, flags, cancellable, (GAsyncReadyCallback) gs_plugin_loader_refresh_finish_sync, &helper); g_main_loop_run (helper.loop); g_main_context_pop_thread_default (helper.context); g_main_loop_unref (helper.loop); g_main_context_unref (helper.context); return helper.ret; }
/* Main method for the native code. This is executed on its own thread. */ void * app_function(void *userdata) { CustomData *data = (CustomData *) userdata; GPlayerDEBUG("Creating pipeline in CustomData at %p", data); /* Create our own GLib Main Context and make it the default one */ data->context = g_main_context_new(); g_main_context_push_thread_default(data->context); data->pipeline = gst_pipeline_new("test-pipeline"); build_pipeline(data); /* Create a GLib Main Loop and set it to run */ GPlayerDEBUG("Entering main loop... (CustomData:%p)", data); data->main_loop = g_main_loop_new(data->context, FALSE); check_initialization_complete(data); g_main_loop_run(data->main_loop); GPlayerDEBUG("Exited main loop"); /* Free resources */ g_main_context_pop_thread_default(data->context); g_main_context_unref(data->context); data->target_state = GST_STATE_NULL; gst_element_set_state(data->pipeline, GST_STATE_NULL); kill_object(data->pipeline); return NULL; }
static void eos_metadata_fetch_data_dispose_impl (EosMetadataFetchData *fetch_data) { g_main_context_pop_thread_default (fetch_data->context); g_clear_pointer (&fetch_data->context, g_main_context_unref); g_clear_object (&fetch_data->task); }
PassRefPtr<AudioBus> AudioFileReader::createBus(float sampleRate, bool mixToMono) { m_sampleRate = sampleRate; m_channels = mixToMono ? 1 : 2; m_frontLeftBuffers = gst_buffer_list_new(); m_frontRightBuffers = gst_buffer_list_new(); GRefPtr<GMainContext> context = adoptGRef(g_main_context_new()); g_main_context_push_thread_default(context.get()); m_loop = adoptGRef(g_main_loop_new(context.get(), FALSE)); // Start the pipeline processing just after the loop is started. GThreadSafeMainLoopSource source; source.schedule("[WebKit] AudioFileReader::decodeAudioForBusCreation", std::function<void()>(std::bind(&AudioFileReader::decodeAudioForBusCreation, this)), G_PRIORITY_DEFAULT, nullptr, context.get()); g_main_loop_run(m_loop.get()); g_main_context_pop_thread_default(context.get()); // Set pipeline to GST_STATE_NULL state here already ASAP to // release any resources that might still be used. gst_element_set_state(m_pipeline, GST_STATE_NULL); if (m_errorOccurred) return 0; RefPtr<AudioBus> audioBus = AudioBus::create(m_channels, m_channelSize, true); audioBus->setSampleRate(m_sampleRate); copyGstreamerBuffersToAudioChannel(m_frontLeftBuffers, audioBus->channel(0)); if (!mixToMono) copyGstreamerBuffersToAudioChannel(m_frontRightBuffers, audioBus->channel(1)); return audioBus; }
static gpointer gst_gl_window_navigation_thread (GstGLWindow * window) { GSource *source; g_return_val_if_fail (GST_IS_GL_WINDOW (window), NULL); window->priv->navigation_context = g_main_context_new (); window->priv->navigation_loop = g_main_loop_new (window->priv->navigation_context, FALSE); g_main_context_push_thread_default (window->priv->navigation_context); source = g_idle_source_new (); g_source_set_callback (source, (GSourceFunc) gst_gl_window_navigation_started, window, NULL); g_source_attach (source, window->priv->navigation_context); g_source_unref (source); g_main_loop_run (window->priv->navigation_loop); g_main_context_pop_thread_default (window->priv->navigation_context); g_main_loop_unref (window->priv->navigation_loop); g_main_context_unref (window->priv->navigation_context); window->priv->navigation_loop = NULL; window->priv->navigation_context = NULL; GST_INFO ("navigation loop exited\n"); return NULL; }
static gboolean gst_gsettings_video_sink_start (GstGSettingsVideoSink * sink) { GError *err = NULL; GThread *thread; sink->loop = g_main_loop_new (sink->context, FALSE); thread = g_thread_create ((GThreadFunc) g_main_loop_run, sink->loop, FALSE, &err); if (!thread) { GST_ELEMENT_ERROR (sink, CORE, STATE_CHANGE, (NULL), ("Failed to create new thread: %s", err->message)); g_error_free (err); g_main_loop_unref (sink->loop); sink->loop = NULL; return FALSE; } g_main_context_push_thread_default (sink->context); sink->settings = g_settings_new (GST_GSETTINGS_SCHEMA); sink->changed_id = g_signal_connect_data (G_OBJECT (sink->settings), "changed", G_CALLBACK (on_changed), gst_object_ref (sink), (GClosureNotify) gst_object_unref, 0); g_main_context_pop_thread_default (sink->context); return TRUE; }
static void get_proxy_uri_async (SoupProxyURIResolver *resolver, SoupURI *uri, GMainContext *async_context, GCancellable *cancellable, SoupProxyURIResolverCallback callback, gpointer user_data) { SoupProxyResolverDefault *resolver_default = SOUP_PROXY_RESOLVER_DEFAULT (resolver); SoupProxyResolverDefaultPrivate *priv = soup_proxy_resolver_default_get_instance_private (resolver_default); SoupAsyncData *async_data; char *uri_string; async_data = g_slice_new0 (SoupAsyncData); async_data->resolver = (SoupProxyURIResolver*) g_object_ref (resolver); async_data->cancellable = cancellable; async_data->callback = callback; async_data->user_data = user_data; uri_string = soup_uri_to_string (uri, FALSE); if (async_context) g_main_context_push_thread_default (async_context); g_proxy_resolver_lookup_async (priv->gproxy_resolver, uri_string, cancellable ? g_object_ref (cancellable) : NULL, resolved_proxy, async_data); if (async_context) g_main_context_pop_thread_default (async_context); g_free (uri_string); }
static gpointer run_main_loop (gpointer data) { (void) data; g_main_context_push_thread_default (main_context); g_main_loop_run (main_loop); g_main_context_pop_thread_default (main_context); return NULL; }
static gpointer async_proxy_test_thread (gpointer num) { GMainContext *context = g_main_context_new (); g_main_context_push_thread_default (context); run_test (GPOINTER_TO_INT (num), FALSE); g_main_context_pop_thread_default (context); g_main_context_unref (context); return NULL; }
static gpointer test1_thread (gpointer use_thread_context) { SoupSession *session; GMainContext *async_context; char *uri; SoupMessage *msg; GMainLoop *loop; /* Wait for main thread to be waiting on test1_cond */ g_mutex_lock (&test1_mutex); g_mutex_unlock (&test1_mutex); async_context = g_main_context_new (); if (use_thread_context) { g_main_context_push_thread_default (async_context); session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, SOUP_SESSION_USE_THREAD_CONTEXT, TRUE, NULL); } else { session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, SOUP_SESSION_ASYNC_CONTEXT, async_context, NULL); } g_main_context_unref (async_context); uri = g_build_filename (base_uri, "slow", NULL); debug_printf (1, " send_message\n"); msg = soup_message_new ("GET", uri); soup_session_send_message (session, msg); soup_test_assert_message_status (msg, SOUP_STATUS_OK); g_object_unref (msg); debug_printf (1, " queue_message\n"); msg = soup_message_new ("GET", uri); loop = g_main_loop_new (async_context, FALSE); g_object_ref (msg); soup_session_queue_message (session, msg, test1_finished, loop); g_main_loop_run (loop); g_main_loop_unref (loop); soup_test_assert_message_status (msg, SOUP_STATUS_OK); g_object_unref (msg); soup_test_session_abort_unref (session); g_free (uri); g_cond_signal (&test1_cond); if (use_thread_context) g_main_context_pop_thread_default (async_context); return NULL; }
/* This is a somewhat hacky way to get FTP to almost work. The proper way to * get FTP to _really_ work involves hacking GIO to have APIs to handle * canoncial URLs. */ static GFile * webkit_soup_request_file_ensure_file_ftp (SoupURI *uri, GCancellable *cancellable, GError **error) { SoupURI *host; char *s; GFile *file, *result; GMount *mount; host = soup_uri_copy_host (uri); s = soup_uri_to_string (host, FALSE); file = g_file_new_for_uri (s); soup_uri_free (host); g_free (s); mount = g_file_find_enclosing_mount (file, cancellable, error); if (mount == NULL && g_file_supports_thread_contexts (file)) { GMainContext *context = g_main_context_new (); GMainLoop *loop = g_main_loop_new (context, FALSE); g_clear_error (error); g_main_context_push_thread_default (context); g_file_mount_enclosing_volume (file, G_MOUNT_MOUNT_NONE, NULL, /* FIXME! */ cancellable, webkit_soup_request_file_ftp_main_loop_quit, loop); g_main_loop_run (loop); g_main_context_pop_thread_default (context); g_main_loop_unref (loop); g_main_context_unref (context); mount = g_file_find_enclosing_mount (file, cancellable, error); } if (mount == NULL) return NULL; g_object_unref (file); file = g_mount_get_default_location (mount); g_object_unref (mount); s = g_strdup (uri->path); if (strchr (s, ';')) *strchr (s, ';') = 0; result = g_file_resolve_relative_path (file, s); g_free (s); g_object_unref (file); return result; }
static void gst_gl_window_default_close (GstGLWindow * window) { GstGLWindowPrivate *priv = window->priv; if (!priv->loop) { priv->alive = FALSE; g_main_context_unref (priv->main_context); priv->main_context = NULL; } else { g_main_context_pop_thread_default (priv->main_context); } }
static void test_gupnp_simple_igd_custom_ctx (void) { GMainContext *mainctx = g_main_context_new (); GUPnPSimpleIgd *igd; g_main_context_push_thread_default (mainctx); igd = gupnp_simple_igd_new (); g_main_context_pop_thread_default (mainctx); run_gupnp_simple_igd_test (mainctx, igd, INTERNAL_PORT); g_object_unref (igd); g_main_context_unref (mainctx); }
void WorkerThread::workerThread() { // Propagate the mainThread's fenv to workers. #if PLATFORM(IOS) FloatingPointEnvironment::singleton().propagateMainThreadEnvironment(); #endif #if PLATFORM(GTK) GRefPtr<GMainContext> mainContext = adoptGRef(g_main_context_new()); g_main_context_push_thread_default(mainContext.get()); #endif { LockHolder lock(m_threadCreationMutex); m_workerGlobalScope = createWorkerGlobalScope(m_startupData->m_scriptURL, m_startupData->m_userAgent, m_startupData->m_contentSecurityPolicyResponseHeaders, m_startupData->m_shouldBypassMainWorldContentSecurityPolicy, WTFMove(m_startupData->m_topOrigin)); if (m_runLoop.terminated()) { // The worker was terminated before the thread had a chance to run. Since the context didn't exist yet, // forbidExecution() couldn't be called from stop(). m_workerGlobalScope->script()->forbidExecution(); } } WorkerScriptController* script = m_workerGlobalScope->script(); script->evaluate(ScriptSourceCode(m_startupData->m_sourceCode, m_startupData->m_scriptURL)); // Free the startup data to cause its member variable deref's happen on the worker's thread (since // all ref/derefs of these objects are happening on the thread at this point). Note that // WorkerThread::~WorkerThread happens on a different thread where it was created. m_startupData = nullptr; runEventLoop(); #if PLATFORM(GTK) g_main_context_pop_thread_default(mainContext.get()); #endif ThreadIdentifier threadID = m_threadID; ASSERT(m_workerGlobalScope->hasOneRef()); // The below assignment will destroy the context, which will in turn notify messaging proxy. // We cannot let any objects survive past thread exit, because no other thread will run GC or otherwise destroy them. m_workerGlobalScope = nullptr; // Clean up WebCore::ThreadGlobalData before WTF::WTFThreadData goes away! threadGlobalData().destroy(); // The thread object may be already destroyed from notification now, don't try to access "this". detachThread(threadID); }
/** * camel_async_closure_free: * @closure: a #CamelAsyncClosure * * Frees the @closure and the resources it holds. * * Since: 3.12 **/ void camel_async_closure_free (CamelAsyncClosure *closure) { g_return_if_fail (closure != NULL); g_main_context_pop_thread_default (closure->context); g_main_loop_unref (closure->loop); g_main_context_unref (closure->context); if (closure->result != NULL) g_object_unref (closure->result); g_slice_free (CamelAsyncClosure, closure); }
static void async_connected (GObject *client, GAsyncResult *result, gpointer data) { SoupSocketAsyncConnectData *sacd = data; SoupSocketPrivate *priv = SOUP_SOCKET_GET_PRIVATE (sacd->sock); GError *error = NULL; GSocketConnection *conn; guint status; if (priv->async_context && !priv->use_thread_context) g_main_context_pop_thread_default (priv->async_context); conn = g_socket_client_connect_finish (G_SOCKET_CLIENT (client), result, &error); status = socket_connected (sacd->sock, conn, error); sacd->callback (sacd->sock, status, sacd->user_data); g_object_unref (sacd->sock); g_slice_free (SoupSocketAsyncConnectData, sacd); }
void RunLoop::run() { RunLoop& runLoop = RunLoop::current(); GMainContext* mainContext = runLoop.m_mainContext.get(); // The innermost main loop should always be there. ASSERT(!runLoop.m_mainLoops.isEmpty()); GMainLoop* innermostLoop = runLoop.m_mainLoops[0].get(); if (!g_main_loop_is_running(innermostLoop)) { g_main_context_push_thread_default(mainContext); g_main_loop_run(innermostLoop); g_main_context_pop_thread_default(mainContext); return; } // Create and run a nested loop if the innermost one was already running. GMainLoop* nestedMainLoop = g_main_loop_new(mainContext, FALSE); runLoop.m_mainLoops.append(adoptGRef(nestedMainLoop)); g_main_context_push_thread_default(mainContext); g_main_loop_run(nestedMainLoop); g_main_context_pop_thread_default(mainContext); runLoop.m_mainLoops.removeLast(); }