コード例 #1
0
ファイル: pk-backend-job.c プロジェクト: dgikiller/PackageKit
/**
 * pk_backend_job_call_vfunc:
 *
 * This method can be called in any thread, and the vfunc is guaranteed
 * to be called idle in the main thread.
 **/
static void
pk_backend_job_call_vfunc (PkBackendJob *job,
			   PkBackendJobSignal signal_kind,
			   gpointer object,
			   GDestroyNotify destroy_func)
{
	PkBackendJobVFuncHelper *helper;
	PkBackendJobVFuncItem *item;
	guint priority = G_PRIORITY_DEFAULT_IDLE;
	_cleanup_source_unref_ GSource *source = NULL;

	/* call transaction vfunc if not disabled and set */
	item = &job->priv->vfunc_items[signal_kind];
	if (!item->enabled || item->vfunc == NULL)
		return;

	/* order this last if others are still pending */
	if (signal_kind == PK_BACKEND_SIGNAL_FINISHED)
		priority = G_PRIORITY_LOW;

	/* emit idle */
	helper = g_new0 (PkBackendJobVFuncHelper, 1);
	helper->job = g_object_ref (job);
	helper->signal_kind = signal_kind;
	helper->object = object;
	helper->destroy_func = destroy_func;
	source = g_idle_source_new ();
	g_source_set_priority (source, priority);
	g_source_set_callback (source,
			       pk_backend_job_call_vfunc_idle_cb,
			       helper,
			       (GDestroyNotify) pk_backend_job_vfunc_event_free);
	g_source_set_name (source, "[PkBackendJob] idle_event_cb");
	g_source_attach (source, NULL);
}
コード例 #2
0
ファイル: gfilemonitor.c プロジェクト: thewb/mokoiax
static void
emit_in_idle (GFileMonitor      *monitor,
	      GFile             *child,
	      GFile             *other_file,
	      GFileMonitorEvent  event_type)
{
  GSource *source;
  FileChange *change;

  change = g_slice_new (FileChange);

  change->monitor = g_object_ref (monitor);
  change->child = g_object_ref (child);
  if (other_file)
    change->other_file = g_object_ref (other_file);
  else
    change->other_file = NULL;
  change->event_type = event_type;

  source = g_idle_source_new ();
  g_source_set_priority (source, 0);

  g_source_set_callback (source, emit_cb, change, (GDestroyNotify)file_change_free);
  g_source_attach (source, NULL);
  g_source_unref (source);
}
コード例 #3
0
ファイル: caja-progress-info.c プロジェクト: City-busz/caja
/* Called with lock held */
static void
queue_idle (CajaProgressInfo *info, gboolean now)
{
    if (info->idle_source == NULL ||
            (now && !info->source_is_now))
    {
        if (info->idle_source)
        {
            g_source_destroy (info->idle_source);
            g_source_unref (info->idle_source);
            info->idle_source = NULL;
        }

        info->source_is_now = now;
        if (now)
        {
            info->idle_source = g_idle_source_new ();
        }
        else
        {
            info->idle_source = g_timeout_source_new (SIGNAL_DELAY_MSEC);
        }
        g_source_set_callback (info->idle_source, idle_callback, info, NULL);
        g_source_attach (info->idle_source, NULL);
    }
}
コード例 #4
0
static void
queue_notification (GObject     *object,
                    const gchar *property_name,
                    GVariant    *value)
{
  GHashTable *notification_queue;
  guint idle_id;
  notification_queue = g_object_get_data (object, "gdbus-codegen-notification-queue");
  if (notification_queue == NULL)
    {
      notification_queue = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) g_variant_unref);
      g_object_set_data_full (object, "gdbus-codegen-notification-queue", notification_queue, (GDestroyNotify) g_hash_table_unref);
    }
  g_hash_table_insert (notification_queue, (gpointer) property_name, (gpointer) value); /* adopts value */
  idle_id = GPOINTER_TO_UINT (g_object_get_data (object, "gdbus-codegen-notification-idle-id"));
  if (idle_id == 0)
    {
      GSource *idle_source;
      idle_source = g_idle_source_new ();
      g_source_set_priority (idle_source, G_PRIORITY_DEFAULT);
      g_source_set_callback (idle_source,
			     emit_notifications_in_idle,
			     g_object_ref (object),
			     (GDestroyNotify) g_object_unref);
      idle_id = g_source_attach (idle_source, g_main_context_get_thread_default ());
      g_source_unref (idle_source);
      g_object_set_data (object, "gdbus-codegen-notification-idle-id", GUINT_TO_POINTER (idle_id));
    }
}
コード例 #5
0
ファイル: gstglwindow.c プロジェクト: fanc999/gst-plugins-bad
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;
}
コード例 #6
0
ファイル: cloud-spy-plugin.cpp プロジェクト: key2/frida-ire
NPError OSCALL
NP_Shutdown (void)
{
  GSource * source;

  source = g_idle_source_new ();
  g_source_set_priority (source, G_PRIORITY_LOW);
  g_source_set_callback (source, cloud_spy_stop_main_loop, NULL, NULL);
  g_source_attach (source, cloud_spy_main_context);
  g_source_unref (source);

  g_thread_join (cloud_spy_main_thread);
  cloud_spy_main_thread = NULL;
  g_main_loop_unref (cloud_spy_main_loop);
  cloud_spy_main_loop = NULL;
  g_main_context_unref (cloud_spy_main_context);
  cloud_spy_main_context = NULL;

  g_hash_table_unref (cloud_spy_plugin_roots);
  cloud_spy_plugin_roots = NULL;
  cloud_spy_nsfuncs = NULL;

  cloud_spy_object_type_deinit ();

  return NPERR_NO_ERROR;
}
コード例 #7
0
static void
hrt_event_loop_glib_quit(HrtEventLoop *loop)
{
    HrtEventLoopGLib *gloop = HRT_EVENT_LOOP_GLIB(loop);
    GSource *source;
    GMainContext *context;

    /* g_main_loop_quit() doesn't reliably work from another thread so
     * we install a one-shot idle to be sure it doesn't get wedged in
     * poll(). https://bugzilla.gnome.org/show_bug.cgi?id=632301
     */

    context = g_main_loop_get_context(gloop->loop);
    g_main_context_ref(context);

    g_main_loop_quit(gloop->loop);
    _hrt_event_loop_set_running(HRT_EVENT_LOOP(gloop), FALSE);

    source = g_idle_source_new();
    g_source_set_callback(source, do_nothing_return_false,
                          NULL, NULL);
    g_source_attach(source, context);
    g_source_unref(source);

    g_main_context_unref(context);
}
コード例 #8
0
ファイル: owr.c プロジェクト: bill-auger/openwebrtc
void _owr_schedule_with_hash_table(GSourceFunc func, GHashTable *hash_table)
{
    GSource *source = g_idle_source_new();

    g_source_set_callback(source, func, hash_table, NULL);
    g_source_attach(source, owr_main_context);
}
コード例 #9
0
ファイル: gimpdbusservice.c プロジェクト: Distrotech/gimp
/*
 * Adds a request to open a file to the end of the queue and
 * starts an idle source if it is not already running.
 */
static gboolean
gimp_dbus_service_queue_open (GimpDBusService *service,
                              const gchar     *uri,
                              gboolean         as_new)
{
  g_queue_push_tail (service->queue,
                     gimp_dbus_service_open_data_new (service, uri, as_new));

  if (! service->source)
    {
      service->source = g_idle_source_new ();

      g_source_set_priority (service->source, G_PRIORITY_LOW);
      g_source_set_callback (service->source,
                             (GSourceFunc) gimp_dbus_service_open_idle, service,
                             NULL);
      g_source_attach (service->source, NULL);
      g_source_unref (service->source);
    }

  /*  The call always succeeds as it is handled in one way or another.
   *  Even presenting an error message is considered success ;-)
   */
  return TRUE;
}
コード例 #10
0
void
_hrt_task_runner_queue_completed_task(HrtTaskRunner *runner,
                                      HrtTask       *task)
{
    /* We want to emit completed signal in the main (runner)
     * thread. The completion idle does nothing if a watcher is added
     * before the completion idle runs.
     */
    g_assert(!_hrt_task_is_completed(task));

    g_mutex_lock(runner->completed_tasks_lock);

    if (runner->completed_tasks_idle_id == 0) {
        GSource *source;
        source = g_idle_source_new();
        g_object_ref(runner);
        g_source_set_callback(source, complete_tasks_in_runner_thread,
                              runner, (GDestroyNotify) g_object_unref);
        g_source_attach(source, runner->runner_context);
        runner->completed_tasks_idle_id = g_source_get_id(source);
        g_source_unref(source);
    }

    g_object_ref(task);
    g_queue_push_tail(&runner->completed_tasks, task);

    g_mutex_unlock(runner->completed_tasks_lock);
}
コード例 #11
0
/**
 * g_io_scheduler_job_send_to_mainloop_async:
 * @job: a #GIOSchedulerJob
 * @func: a #GSourceFunc callback that will be called in the original thread
 * @user_data: data to pass to @func
 * @notify: (nullable): a #GDestroyNotify for @user_data, or %NULL
 * 
 * Used from an I/O job to send a callback to be run asynchronously in
 * the thread that the job was started from. The callback will be run
 * when the main loop is available, but at that time the I/O job might
 * have finished. The return value from the callback is ignored.
 *
 * Note that if you are passing the @user_data from g_io_scheduler_push_job()
 * on to this function you have to ensure that it is not freed before
 * @func is called, either by passing %NULL as @notify to 
 * g_io_scheduler_push_job() or by using refcounting for @user_data.
 *
 * Deprecated: Use g_main_context_invoke().
 **/
void
g_io_scheduler_job_send_to_mainloop_async (GIOSchedulerJob *job,
					   GSourceFunc      func,
					   gpointer         user_data,
					   GDestroyNotify   notify)
{
  GSource *source;
  MainLoopProxy *proxy;

  g_return_if_fail (job != NULL);
  g_return_if_fail (func != NULL);

  proxy = g_new0 (MainLoopProxy, 1);
  proxy->func = func;
  proxy->data = user_data;
  proxy->notify = notify;
  g_mutex_init (&proxy->ack_lock);
  g_cond_init (&proxy->ack_condition);

  source = g_idle_source_new ();
  g_source_set_priority (source, G_PRIORITY_DEFAULT);
  g_source_set_callback (source, mainloop_proxy_func, proxy,
			 (GDestroyNotify)mainloop_proxy_free);
  g_source_set_name (source, "[gio] mainloop_proxy_func");

  g_source_attach (source, job->context);
  g_source_unref (source);
}
コード例 #12
0
static gboolean
gst_mio_video_src_perform (GstMIOVideoSrc * self, GstMIOCallback cb,
    gpointer data)
{
  GstMIOPerformCtx ctx;
  GSource *source;

  ctx.self = self;
  ctx.callback = cb;
  ctx.data = data;
  ctx.result = FALSE;

  ctx.mutex = g_mutex_new ();
  ctx.cond = g_cond_new ();
  ctx.finished = FALSE;

  source = g_idle_source_new ();
  g_source_set_callback (source, gst_mio_video_src_perform_proxy, &ctx, NULL);
  g_source_attach (source, self->dispatcher_ctx);

  g_mutex_lock (ctx.mutex);
  while (!ctx.finished)
    g_cond_wait (ctx.cond, ctx.mutex);
  g_mutex_unlock (ctx.mutex);

  g_source_destroy (source);
  g_source_unref (source);

  g_cond_free (ctx.cond);
  g_mutex_free (ctx.mutex);

  return ctx.result;
}
コード例 #13
0
void idle_test()
{
	int user_data = 0;
	gboolean retVal;
	GSource *s = g_idle_source_new();

	idle_loop = g_main_loop_new(NULL, FALSE);
	g_source_attach(s,context);

	g_idle_add((GSourceFunc)function,&user_data);

	retVal = g_idle_remove_by_data(&user_data);

	//checks g_idle_remove_by_data
	g_assert(retVal == TRUE);
	retVal = FALSE;

	g_idle_add((GSourceFunc)function,&user_data);

	retVal = g_source_remove_by_user_data(&user_data);

	//checks g_source_remove_by_user_data
	g_assert(retVal == TRUE);

	g_idle_add((GSourceFunc)function,&user_data);

	g_main_loop_run(idle_loop);

	g_main_loop_unref(idle_loop);

	//checks whether the function was run or not
	g_assert(user_data == 1);
}
コード例 #14
0
void IpcClientHost::onDisconnected()
{
	g_message("%s (%d): Disconnected", __PRETTY_FUNCTION__, __LINE__);

	m_clearing = true;

	for (WindowMap::const_iterator it = m_winMap.begin(); it != m_winMap.end(); ++it) {
		static_cast<HostWindow*>(it->second)->channelRemoved();
		static_cast<HostWindow*>(it->second)->setClientHost(0);
		WindowServer::instance()->removeWindow(it->second);
	}

	m_winMap.clear();
	m_winSet.clear();
	m_closedWinSet.clear();

	// http://bugreports.qt.nokia.com/browse/QTBUG-18434: deleteLater does
	// not work when used in a g_idle_dispatch
	//deleteLater();
	if (!m_idleDestroySrc) {
		GSource* src = g_idle_source_new();
		g_source_set_callback(src, (GSourceFunc) idleDestroyCallback, this, NULL);
		g_source_attach(src, g_main_loop_get_context(IpcServer::instance()->mainLoop()));
		m_idleDestroySrc = src;
	}
}
コード例 #15
0
static void
process_app_info (CcNotificationsPanel *panel,
                  GTask                *task,
                  GAppInfo             *app_info)
{
  Application *app;
  char *app_id;
  char *canonical_app_id;
  char *path;
  GSettings *settings;
  GSource *source;

  app_id = app_info_get_id (app_info);
  canonical_app_id = g_strcanon (app_id,
                                 "0123456789"
                                 "abcdefghijklmnopqrstuvwxyz"
                                 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                                 "-",
                                 '-');

  path = g_strconcat (APP_PREFIX, canonical_app_id, "/", NULL);
  settings = g_settings_new_with_path (APP_SCHEMA, path);

  app = g_slice_new (Application);
  app->canonical_app_id = canonical_app_id;
  app->settings = settings;
  app->app_info = g_object_ref (app_info);
  app->panel = g_object_ref (panel);

  source = g_idle_source_new ();
  g_source_set_callback (source, queued_app_info, app, NULL);
  g_source_attach (source, g_task_get_context (task));

  g_free (path);
}
コード例 #16
0
static void
delete_port_mapping_cb (GUPnPService *service,
    GUPnPServiceAction *action,
    gpointer user_data)
{
  guint requested_external_port = GPOINTER_TO_UINT (user_data);
  gchar *remote_host = NULL;
  guint external_port = 0;
  gchar *proto = NULL;

  gupnp_service_action_get (action,
      "NewRemoteHost", G_TYPE_STRING, &remote_host,
      "NewExternalPort", G_TYPE_UINT, &external_port,
      "NewProtocol", G_TYPE_STRING, &proto,
      NULL);

  g_assert (remote_host != NULL);
  if (requested_external_port || !return_conflict)
    g_assert (external_port == INTERNAL_PORT);
  else
    g_assert (external_port != INTERNAL_PORT);
  g_assert (proto && !strcmp (proto, "UDP"));

  gupnp_service_action_return (action);

  g_free (remote_host);
  g_free (proto);

  GSource* src = g_idle_source_new ();
  g_source_set_callback (src, loop_quit, NULL, NULL);
  g_source_attach (src, g_main_context_get_thread_default ());
}
static GstFlowReturn
gst_soup_http_client_sink_render (GstBaseSink * sink, GstBuffer * buffer)
{
  GstSoupHttpClientSink *souphttpsink = GST_SOUP_HTTP_CLIENT_SINK (sink);
  GSource *source;
  gboolean wake;

  if (souphttpsink->status_code != 0) {
    GST_ELEMENT_ERROR (souphttpsink, RESOURCE, WRITE,
        ("Could not write to HTTP URI"),
        ("status: %d %s", souphttpsink->status_code,
            souphttpsink->reason_phrase));
    return GST_FLOW_ERROR;
  }

  g_mutex_lock (&souphttpsink->mutex);
  if (souphttpsink->location != NULL) {
    wake = (souphttpsink->queued_buffers == NULL);
    souphttpsink->queued_buffers =
        g_list_append (souphttpsink->queued_buffers, gst_buffer_ref (buffer));

    if (wake) {
      GST_DEBUG_OBJECT (souphttpsink, "setting callback for new buffers");
      source = g_idle_source_new ();
      g_source_set_callback (source, (GSourceFunc) (send_message),
          souphttpsink, NULL);
      g_source_attach (source, souphttpsink->context);
      g_source_unref (source);
    }
  }
  g_mutex_unlock (&souphttpsink->mutex);

  return GST_FLOW_OK;
}
コード例 #18
0
static void
queue_network_changed (GNetworkMonitorBase *monitor)
{
  if (!monitor->priv->network_changed_source)
    {
      GSource *source;

      source = g_idle_source_new ();
      /* Use G_PRIORITY_HIGH_IDLE priority so that multiple
       * network-change-related notifications coming in at
       * G_PRIORITY_DEFAULT will get coalesced into one signal
       * emission.
       */
      g_source_set_priority (source, G_PRIORITY_HIGH_IDLE);
      g_source_set_callback (source, emit_network_changed, monitor, NULL);
      g_source_attach (source, monitor->priv->context);
      monitor->priv->network_changed_source = source;
    }

  /* Normally we wait to update is_available until we emit the signal,
   * to keep things consistent. But when we're first creating the
   * object, we want it to be correct right away.
   */
  if (monitor->priv->initializing)
    {
      monitor->priv->is_available = (monitor->priv->have_ipv4_default_route ||
                                     monitor->priv->have_ipv6_default_route);
    }
}
コード例 #19
0
ファイル: char-pty.c プロジェクト: pfliu/qemu
/* Called with chr_write_lock held.  */
static void pty_chr_state(Chardev *chr, int connected)
{
    PtyChardev *s = PTY_CHARDEV(chr);

    if (!connected) {
        if (s->open_source) {
            g_source_destroy(s->open_source);
            g_source_unref(s->open_source);
            s->open_source = NULL;
        }
        remove_fd_in_watch(chr);
        s->connected = 0;
        /* (re-)connect poll interval for idle guests: once per second.
         * We check more frequently in case the guests sends data to
         * the virtual device linked to our pty. */
        pty_chr_rearm_timer(chr, 1000);
    } else {
        pty_chr_timer_cancel(s);
        if (!s->connected) {
            g_assert(s->open_source == NULL);
            s->open_source = g_idle_source_new();
            s->connected = 1;
            g_source_set_callback(s->open_source,
                                  qemu_chr_be_generic_open_func,
                                  chr, NULL);
            g_source_attach(s->open_source, chr->gcontext);
        }
        if (!chr->gsource) {
            chr->gsource = io_add_watch_poll(chr, s->ioc,
                                               pty_chr_read_poll,
                                               pty_chr_read,
                                               chr, chr->gcontext);
        }
    }
}
コード例 #20
0
static void
gst_v4l2_device_provider_stop (GstDeviceProvider * provider)
{
  GstV4l2DeviceProvider *self = GST_V4L2_DEVICE_PROVIDER (provider);
  GMainContext *context;
  GMainLoop *loop;
  GSource *idle_stop_source;

  GST_OBJECT_LOCK (self);
  context = self->context;
  loop = self->loop;
  self->context = NULL;
  self->loop = NULL;
  GST_OBJECT_UNLOCK (self);

  if (!context || !loop)
    return;

  idle_stop_source = g_idle_source_new ();
  g_source_set_callback (idle_stop_source, (GSourceFunc) g_main_loop_quit, loop,
      (GDestroyNotify) g_main_loop_unref);
  g_source_attach (idle_stop_source, context);
  g_source_unref (idle_stop_source);
  g_main_context_unref (context);

  g_thread_join (self->thread);
  self->thread = NULL;
  self->started = FALSE;
}
コード例 #21
0
void WorkQueue::scheduleWork(PassOwnPtr<WorkItem> item)
{
    GRefPtr<GSource> dispatchSource = adoptGRef(g_idle_source_new());
    ASSERT(dispatchSource);
    g_source_set_priority(dispatchSource.get(), G_PRIORITY_DEFAULT);

    scheduleWorkOnSource(dispatchSource.get(), item, reinterpret_cast<GSourceFunc>(&WorkQueue::EventSource::performWorkOnce));
}
コード例 #22
0
void WorkQueue::dispatch(const Function<void()>& function)
{
    GRefPtr<GSource> dispatchSource = adoptGRef(g_idle_source_new());
    ASSERT(dispatchSource);
    g_source_set_priority(dispatchSource.get(), G_PRIORITY_DEFAULT);

    dispatchOnSource(dispatchSource.get(), function, reinterpret_cast<GSourceFunc>(&WorkQueue::EventSource::performWorkOnce));
}
コード例 #23
0
ファイル: RunLoopGtk.cpp プロジェクト: iArnaud/webkitnix
void RunLoop::wakeUp()
{
    GRefPtr<GSource> source = adoptGRef(g_idle_source_new());
    g_source_set_priority(source.get(), G_PRIORITY_DEFAULT);
    g_source_set_callback(source.get(), reinterpret_cast<GSourceFunc>(&RunLoop::queueWork), this, 0);
    g_source_attach(source.get(), m_runLoopContext.get());

    g_main_context_wakeup(m_runLoopContext.get());
}
コード例 #24
0
ファイル: cockpitstream.c プロジェクト: systemd/cockpit
static void
cockpit_close_later (CockpitStream *self)
{
  GSource *source = g_idle_source_new ();
  g_source_set_priority (source, G_PRIORITY_HIGH);
  g_source_set_callback (source, on_later_close, g_object_ref (self), g_object_unref);
  g_source_attach (source, g_main_context_get_thread_default ());
  g_source_unref (source);
}
コード例 #25
0
ファイル: io_thread.c プロジェクト: andrewrk/mpd
guint
io_thread_idle_add(GSourceFunc function, gpointer data)
{
	GSource *source = g_idle_source_new();
	g_source_set_callback(source, function, data, NULL);
	guint id = g_source_attach(source, io.context);
	g_source_unref(source);
	return id;
}
コード例 #26
0
ファイル: soup-misc.c プロジェクト: ChingezKhan/libsoup
/**
 * soup_add_idle:
 * @async_context: the #GMainContext to dispatch the idle event in, or
 * %NULL for the default context
 * @function: the callback to invoke at idle time
 * @data: user data to pass to @function
 *
 * Adds an idle event as with g_idle_add(), but using the given
 * @async_context.
 *
 * If you want @function to run "right away", use
 * soup_add_completion(), since that sets a higher priority on the
 * #GSource than soup_add_idle() does.
 *
 * Return value: a #GSource, which can be removed from @async_context
 * with g_source_destroy().
 **/
GSource *
soup_add_idle (GMainContext *async_context,
	       GSourceFunc function, gpointer data)
{
	GSource *source = g_idle_source_new ();
	g_source_set_callback (source, function, data, NULL);
	g_source_attach (source, async_context);
	g_source_unref (source);
	return source;
}
コード例 #27
0
static void CALEStartEventLoop(void * data)
{
    CALEContext * const context = data;

    assert(context != NULL);

    // Create the event loop.
    GMainContext * const loop_context = g_main_context_new();
    GMainLoop * const event_loop = g_main_loop_new(loop_context, FALSE);

    g_main_context_push_thread_default(loop_context);

    /*
      We have to do the BlueZ object manager client initialization and
      signal subscription here so that the corresponding asynchronous
      signal handling occurs in the same thread as the one running the
      GLib event loop.
    */
    if (CALESetUpDBus(&g_context))
    {
        ca_mutex_lock(context->lock);

        assert(context->event_loop == NULL);
        context->event_loop = event_loop;

        ca_mutex_unlock(context->lock);

        /*
          Add an idle handler that notifies a thread waiting for the
          GLib event loop to run that the event loop is actually
          running.  We do this in the context of the event loop itself
          to avoid race conditions.
        */
        GSource * const source = g_idle_source_new();
        g_source_set_priority(source, G_PRIORITY_HIGH_IDLE);
        g_source_set_callback(source,
                              CALEEventLoopStarted,
                              &context->le_started,  // data
                              NULL);                 // notify
        (void) g_source_attach(source, loop_context);
        g_source_unref(source);

        g_main_loop_run(event_loop);  // Blocks until loop is quit.

        CALETearDownDBus(&g_context);
    }

    /*
      Clean up in the same thread to avoid having to explicitly bump
      the ref count to retain ownership.
    */
    g_main_context_unref(loop_context);
    g_main_loop_unref(event_loop);
}
コード例 #28
0
ファイル: soup-misc.c プロジェクト: ChingezKhan/libsoup
/**
 * soup_add_completion:
 * @async_context: the #GMainContext to dispatch the idle event in, or
 * %NULL for the default context
 * @function: the callback to invoke
 * @data: user data to pass to @function
 *
 * Adds @function to be executed from inside @async_context with the
 * default priority. Use this when you want to complete an action in
 * @async_context's main loop, as soon as possible.
 *
 * Return value: a #GSource, which can be removed from @async_context
 * with g_source_destroy().
 *
 * Since: 2.24
 **/
GSource *
soup_add_completion (GMainContext *async_context,
	             GSourceFunc function, gpointer data)
{
	GSource *source = g_idle_source_new ();
	g_source_set_priority (source, G_PRIORITY_DEFAULT);
	g_source_set_callback (source, function, data, NULL);
	g_source_attach (source, async_context);
	g_source_unref (source);
	return source;
}
コード例 #29
0
ファイル: frida-glue.c プロジェクト: lq10secboy/frida-core
void
frida_unref (gpointer obj)
{
  GSource * source;

  source = g_idle_source_new ();
  g_source_set_priority (source, G_PRIORITY_HIGH);
  g_source_set_callback (source, dummy_callback, obj, g_object_unref);
  g_source_attach (source, main_context);
  g_source_unref (source);
}
コード例 #30
0
ファイル: select.c プロジェクト: annag42/barnowl
void owl_select_post_task(void (*cb)(void*), void *cbdata, void (*destroy_cbdata)(void*), GMainContext *context)
{
  GSource *source = g_idle_source_new();
  owl_task *t = g_new0(owl_task, 1);
  t->cb = cb;
  t->cbdata = cbdata;
  t->destroy_cbdata = destroy_cbdata;
  g_source_set_priority(source, G_PRIORITY_DEFAULT);
  g_source_set_callback(source, _run_task, t, _destroy_task);
  g_source_attach(source, context);
  g_source_unref(source);
}