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 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 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 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); }
/** * soup_socket_connect_async: * @sock: a client #SoupSocket (which must not already be connected) * @cancellable: a #GCancellable, or %NULL * @callback: (scope async): callback to call after connecting * @user_data: data to pass to @callback * * Begins asynchronously connecting to @sock's remote address. The * socket will call @callback when it succeeds or fails (but not * before returning from this function). * * If @cancellable is non-%NULL, it can be used to cancel the * connection. @callback will still be invoked in this case, with a * status of %SOUP_STATUS_CANCELLED. **/ void soup_socket_connect_async (SoupSocket *sock, GCancellable *cancellable, SoupSocketCallback callback, gpointer user_data) { SoupSocketPrivate *priv; SoupSocketAsyncConnectData *sacd; GSocketClient *client; g_return_if_fail (SOUP_IS_SOCKET (sock)); priv = SOUP_SOCKET_GET_PRIVATE (sock); g_return_if_fail (priv->remote_addr != NULL); sacd = g_slice_new0 (SoupSocketAsyncConnectData); sacd->sock = g_object_ref (sock); sacd->callback = callback; sacd->user_data = user_data; priv->connect_cancel = cancellable ? g_object_ref (cancellable) : g_cancellable_new (); if (priv->async_context && !priv->use_thread_context) g_main_context_push_thread_default (priv->async_context); client = new_socket_client (sock); g_socket_client_connect_async (client, G_SOCKET_CONNECTABLE (priv->remote_addr), priv->connect_cancel, async_connected, sacd); g_object_unref (client); }
/** * 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; }
/* * ajax_worker_run */ gpointer ajax_worker_run ( ajax_worker *aw ) { log_print ( "ajax-%u: worker entering event loop.\n", aw->uid ); /* spawn main loop driver */ aw->context = g_main_context_new ( ); aw->mainloop = g_main_loop_new ( aw->context, FALSE ); g_main_context_push_thread_default ( aw->context ); /* attach socket */ if ( listen(aw->server_socket, AJAX_QUEUE_SIZE) != 0 ) { log_print ( "ajax-%u: unable to listen on socket: %s", aw->uid, strerror(errno) ); return NULL; } aw->server_chan = g_io_channel_unix_new ( aw->server_socket ); aw->server_src = g_io_create_watch ( aw->server_chan, G_IO_IN ); g_source_set_callback ( aw->server_src, (GSourceFunc)handle_new_connection, aw, NULL ); g_source_attach ( aw->server_src, aw->context ); /* enter main loop */ aw->nb_requests = 0; g_timeout_add_seconds ( 60, (GSourceFunc)handle_alive_timeout, aw ); g_main_loop_run ( aw->mainloop ); return NULL; }
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; }
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; }
/** * 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); }
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; }
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); }
/* 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; }
/** * 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; }
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; }
/** * 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; }
/** * 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; }
/** * 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; }
/* 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; }
gpointer Shell::launchWPE(gpointer data) { Shell::m_instance = static_cast<Shell*>(data); GMainContext* threadContext = g_main_context_new(); GMainLoop* threadLoop = g_main_loop_new(threadContext, FALSE); g_main_context_push_thread_default(threadContext); auto pageGroupIdentifier = adoptWK(WKStringCreateWithUTF8CString("WPEPageGroup")); auto pageGroup = adoptWK(WKPageGroupCreateWithIdentifier(pageGroupIdentifier.get())); auto context = adoptWK(WKContextCreate()); Shell::instance().m_view = adoptWK(WKViewCreate(context.get(), pageGroup.get())); auto view = Shell::instance().m_view.get(); WKViewResize(view, Shell::instance().m_environment.outputSize()); WKViewMakeWPEInputTarget(view); const char* url = g_getenv("WPE_SHELL_URL"); if (!url) url = "http://www.webkit.org/blog-files/3d-transforms/poster-circle.html"; auto shellURL = adoptWK(WKURLCreateWithUTF8CString(url)); WKPageLoadURL(WKViewGetPage(view), shellURL.get()); g_main_loop_run(threadLoop); return nullptr; }
QEventDispatcherGlibPrivate::QEventDispatcherGlibPrivate(GMainContext *context) : mainContext(context) { #if GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 32 if (qEnvironmentVariableIsEmpty("QT_NO_THREADED_GLIB")) { static QBasicMutex mutex; QMutexLocker locker(&mutex); if (!g_thread_supported()) g_thread_init(NULL); } #endif if (mainContext) { g_main_context_ref(mainContext); } else { QCoreApplication *app = QCoreApplication::instance(); if (app && QThread::currentThread() == app->thread()) { mainContext = g_main_context_default(); g_main_context_ref(mainContext); } else { mainContext = g_main_context_new(); } } #if GLIB_CHECK_VERSION (2, 22, 0) g_main_context_push_thread_default (mainContext); #endif // setup post event source postEventSource = reinterpret_cast<GPostEventSource *>(g_source_new(&postEventSourceFuncs, sizeof(GPostEventSource))); postEventSource->serialNumber.store(1); postEventSource->d = this; g_source_set_can_recurse(&postEventSource->source, true); g_source_attach(&postEventSource->source, mainContext); // setup socketNotifierSource socketNotifierSource = reinterpret_cast<GSocketNotifierSource *>(g_source_new(&socketNotifierSourceFuncs, sizeof(GSocketNotifierSource))); (void) new (&socketNotifierSource->pollfds) QList<GPollFDWithQSocketNotifier *>(); g_source_set_can_recurse(&socketNotifierSource->source, true); g_source_attach(&socketNotifierSource->source, mainContext); // setup normal and idle timer sources timerSource = reinterpret_cast<GTimerSource *>(g_source_new(&timerSourceFuncs, sizeof(GTimerSource))); (void) new (&timerSource->timerList) QTimerInfoList(); timerSource->processEventsFlags = QEventLoop::AllEvents; timerSource->runWithIdlePriority = false; g_source_set_can_recurse(&timerSource->source, true); g_source_attach(&timerSource->source, mainContext); idleTimerSource = reinterpret_cast<GIdleTimerSource *>(g_source_new(&idleTimerSourceFuncs, sizeof(GIdleTimerSource))); idleTimerSource->timerSource = timerSource; g_source_set_can_recurse(&idleTimerSource->source, true); g_source_set_priority(&idleTimerSource->source, G_PRIORITY_DEFAULT_IDLE); g_source_attach(&idleTimerSource->source, mainContext); }
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 owr_run(gpointer data) { g_return_val_if_fail(!data, NULL); g_main_context_push_thread_default(owr_main_context); g_main_loop_run(owr_main_loop); return NULL; }
static void * connman_thread(void *aux) { GError *err; GDBusProxy *mgr; GMainContext *ctx = g_main_context_new(); GMainLoop *mainloop = g_main_loop_new(ctx, FALSE); connman_courier = glib_courier_create(ctx); g_main_context_push_thread_default(ctx); again: err = NULL; mgr = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START , NULL, "net.connman", "/", "net.connman.Manager", NULL, &err); if(mgr == NULL) { TRACE(TRACE_ERROR, "CONNMAN", "Unable to connect to connman -- %s", err->message); g_error_free(err); sleep(5); goto again; } g_signal_connect(G_OBJECT(mgr), "g-signal", G_CALLBACK(connman_mgr_signal), NULL); g_bus_own_name(G_BUS_TYPE_SYSTEM, "com.showtimemediacenter.showtime.network.agent", G_BUS_NAME_OWNER_FLAGS_NONE, on_bus_acquired, on_name_acquired, on_name_lost, mgr, NULL); connman_getpropreties(mgr); connman_getservices(mgr); connman_gettechnologies(mgr); if(have_wifi) { setting_create(SETTING_BOOL, connman_settings, SETTINGS_INITIAL_UPDATE, SETTING_TITLE(_p("Enable Wi-Fi")), SETTING_CALLBACK(set_wifi_enable, NULL), SETTING_STORE("connman", "enable_wifi"), NULL); } g_main_loop_run(mainloop); return NULL; }
gboolean GstPipeliner::push_thread_context(gpointer user_data) { auto context = static_cast<GstPipeliner*>(user_data); g_main_context_push_thread_default(context->main_loop_->get_main_context()); gst_bus_add_watch( gst_pipeline_get_bus(GST_PIPELINE(context->get_pipeline())), bus_watch, user_data); return FALSE; }
void CAStartBleGattClientThread(void *data) { OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "IN"); ca_mutex_lock(g_bleClientStateMutex); if (true == g_isBleGattClientStarted) { OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "Gatt Client is already running!!"); ca_mutex_unlock(g_bleClientStateMutex); return; } CAResult_t ret = CABleGattSetScanParameter(); if (CA_STATUS_OK != ret) { OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "CABleSetScanParameter Failed"); ca_mutex_unlock(g_bleClientStateMutex); CATerminateLEGattClient(); return; } ret = CABleGattSetCallbacks(); if (CA_STATUS_OK != ret) { OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "CABleGattSetCallbacks Failed"); ca_mutex_unlock(g_bleClientStateMutex); CATerminateLEGattClient(); return; } OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "Starting LE device discovery"); ret = CABleGattStartDeviceDiscovery(); if (CA_STATUS_OK != ret) { OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "bt_adapter_le_start_device_discovery Failed"); ca_mutex_unlock(g_bleClientStateMutex); CATerminateLEGattClient(); return; } g_isBleGattClientStarted = true; ca_mutex_unlock(g_bleClientStateMutex); OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "Giveing the control to threadPool"); GMainContext *thread_context = g_main_context_new(); g_eventLoop = g_main_loop_new(thread_context, FALSE); g_main_context_push_thread_default(thread_context); g_main_loop_run(g_eventLoop); OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "OUT"); }
static gpointer infinoted_plugin_dbus_thread_func(gpointer plugin_info) { InfinotedPluginDbus* plugin; plugin = (InfinotedPluginDbus*)plugin_info; g_mutex_lock(&plugin->mutex); if(plugin->thread == NULL) { g_mutex_unlock(&plugin->mutex); return NULL; } plugin->context = g_main_context_new(); g_main_context_push_thread_default(plugin->context); plugin->loop = g_main_loop_new(plugin->context, FALSE); g_mutex_unlock(&plugin->mutex); plugin->id = g_bus_own_name( plugin->bus_type, plugin->bus_name, G_BUS_NAME_OWNER_FLAGS_NONE, infinoted_plugin_dbus_bus_acquired_func, infinoted_plugin_dbus_name_acquired_func, infinoted_plugin_dbus_name_lost_func, plugin, NULL ); g_main_loop_run(plugin->loop); g_bus_unown_name(plugin->id); plugin->id = 0; /* TODO: This is an enormous hack. Apparently, g_bus_own_name starts some * thread internally, and that thread is not stopped by g_bus_unown_name. * When the plugin is then unloaded, it leads to a crash because the thread * is still doing some cleanup work. I don't see a possibility for us here * to wait for that thread to finish, so we simply wait 100ms. * * Waiting with quitting the main loop until either bus_acquired or * name_lost are called does not help. * * A solution might be to not use the g_bus_own_name and g_bus_unown_name * APIs, but some more low-level APIs. */ g_usleep(100000); g_mutex_lock(&plugin->mutex); g_main_loop_unref(plugin->loop); plugin->loop = NULL; g_main_context_unref(plugin->context); plugin->context = NULL; g_mutex_unlock(&plugin->mutex); return NULL; }
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; }
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(); }