Ejemplo n.º 1
0
void WorkQueue::platformInvalidate()
{
    MutexLocker locker(m_eventLoopLock);

    if (m_eventLoop) {
        if (g_main_loop_is_running(m_eventLoop))
            g_main_loop_quit(m_eventLoop);

        g_main_loop_unref(m_eventLoop);
        m_eventLoop = 0;
    }

    if (m_eventContext) {
        g_main_context_unref(m_eventContext);
        m_eventContext = 0;
    }
}
Ejemplo n.º 2
0
void
ToolsCore_Setup(ToolsServiceState *state)
{
   GMainContext *gctx;
   ToolsServiceProperty ctxProp = { TOOLS_CORE_PROP_CTX };

   if (!g_thread_supported()) {
      g_thread_init(NULL);
   }

   /*
    * Useful for debugging purposes. Log the vesion and build information.
    */
   g_message("Tools Version: %s (%s)\n", TOOLS_VERSION_EXT_CURRENT_STR, BUILD_NUMBER);

   /* Initializes the app context. */
   gctx = g_main_context_default();
   state->ctx.version = TOOLS_CORE_API_V1;
   state->ctx.name = state->name;
   state->ctx.errorCode = EXIT_SUCCESS;
#if defined(__APPLE__)
   /*
    * Mac OS doesn't use g_main_loop_run(), so need to create the loop as
    * "running".
    */
   state->ctx.mainLoop = g_main_loop_new(gctx, TRUE);
#else
   state->ctx.mainLoop = g_main_loop_new(gctx, FALSE);
#endif
   state->ctx.isVMware = VmCheck_IsVirtualWorld();
   g_main_context_unref(gctx);

   g_type_init();
   state->ctx.serviceObj = g_object_new(TOOLSCORE_TYPE_SERVICE, NULL);

   /* Register the core properties. */
   ToolsCoreService_RegisterProperty(state->ctx.serviceObj,
                                     &ctxProp);
   g_object_set(state->ctx.serviceObj, TOOLS_CORE_PROP_CTX, &state->ctx, NULL);
   ToolsCorePool_Init(&state->ctx);

   /* Initializes the debug library if needed. */
   if (state->debugPlugin != NULL) {
      ToolsCoreInitializeDebug(state);
   }
}
Ejemplo n.º 3
0
/* main function run by each thread, which submit jobs */
static gpointer
test9_main_func (GdaWorker *worker)
{
	GError *error = NULL;
	GMainContext *context = NULL;
	static guint counter = 0;

	context = g_main_context_new ();

	if (! gda_worker_set_callback (worker, context, (GdaWorkerCallback) test9_worker_cb, g_thread_self (), &error)) {
		g_print ("gda_worker_set_callback() from thread %p error: %s\n", g_thread_self (),
			 error && error->message ? error->message : "No detail");
		g_clear_error (&error);
		return (gpointer) 0x01;
	}

	GMainLoop *loop;
	loop = g_main_loop_new (context, FALSE);
#define N_JOBS 2
	guint i;
	for (i = 0; i < N_JOBS; i++) {
		guint jid;
		Test9Data *data;
		data = g_new (Test9Data, 1);
		data->in = (guint) GPOINTER_TO_INT (g_thread_self ()) + (counter++);
		data->out = 0;
		data->loop = (i == N_JOBS - 1) ? loop : NULL;
		jid = gda_worker_submit_job (worker, context, (GdaWorkerFunc) test9_job_func, data,
					     NULL, (GDestroyNotify) test9data_free, &error);
		if (jid == 0) {
			g_print ("gda_worker_submit_job() from thread %p error: %s\n", g_thread_self (),
				 error && error->message ? error->message : "No detail");
			g_clear_error (&error);
			return (gpointer) 0x01;
		}
		else
			g_print ("Submitted job %u from thread %p, with data %p\n", jid, g_thread_self(), data);
	}
				     
	g_main_loop_run (loop);
	g_main_loop_unref (loop);

	g_main_context_unref (context);
	return NULL;
}
Ejemplo n.º 4
0
void
frida_deinit (void)
{
  g_assert (main_loop != NULL);

  if (main_thread != NULL)
    frida_shutdown ();

  g_main_loop_unref (main_loop);
  main_loop = NULL;
  g_main_context_unref (main_context);
  main_context = NULL;

#if GLIB_CHECK_VERSION (2, 46, 0)
  gio_deinit ();
  glib_deinit ();
#endif
}
Ejemplo n.º 5
0
void
frida_deinit (void)
{
  g_assert (main_loop != NULL);

  if (main_thread != NULL)
    frida_shutdown ();

  g_main_loop_unref (main_loop);
  main_loop = NULL;
  g_main_context_unref (main_context);
  main_context = NULL;

  gio_shutdown ();
  glib_shutdown ();
  gio_deinit ();
  glib_deinit ();
}
Ejemplo n.º 6
0
static void
gst_video_convert_frame_context_free (GstVideoConvertFrameContext * ctx)
{
  /* Wait until all users of the mutex are done */
  g_mutex_lock (ctx->mutex);
  g_mutex_unlock (ctx->mutex);
  g_mutex_free (ctx->mutex);
  if (ctx->timeout_id)
    g_source_remove (ctx->timeout_id);
  if (ctx->buffer)
    gst_buffer_unref (ctx->buffer);
  g_main_context_unref (ctx->context);

  gst_element_set_state (ctx->pipeline, GST_STATE_NULL);
  gst_object_unref (ctx->pipeline);

  g_slice_free (GstVideoConvertFrameContext, ctx);
}
Ejemplo n.º 7
0
void
io_thread_deinit(void)
{
	if (io.thread != NULL) {
		io_thread_quit();

		g_thread_join(io.thread);
	}

	if (io.loop != NULL)
		g_main_loop_unref(io.loop);

	if (io.context != NULL)
		g_main_context_unref(io.context);

	g_cond_free(io.cond);
	g_mutex_free(io.mutex);
}
Ejemplo n.º 8
0
static SoupServer *
test_server_new (gboolean in_own_thread, gboolean ssl)
{
	SoupServer *server;
	GMainContext *async_context;
	const char *ssl_cert_file, *ssl_key_file;
	SoupAddress *addr;

	async_context = in_own_thread ? g_main_context_new () : NULL;

	if (ssl) {
		ssl_cert_file = SRCDIR "/test-cert.pem";
		ssl_key_file = SRCDIR "/test-key.pem";
	} else
		ssl_cert_file = ssl_key_file = NULL;

	addr = soup_address_new ("127.0.0.1", SOUP_ADDRESS_ANY_PORT);
	soup_address_resolve_sync (addr, NULL);

	server = soup_server_new (SOUP_SERVER_INTERFACE, addr,
				  SOUP_SERVER_ASYNC_CONTEXT, async_context,
				  SOUP_SERVER_SSL_CERT_FILE, ssl_cert_file,
				  SOUP_SERVER_SSL_KEY_FILE, ssl_key_file,
				  NULL);
	g_object_unref (addr);
	if (async_context)
		g_main_context_unref (async_context);

	if (!server) {
		fprintf (stderr, "Unable to create server\n");
		exit (1);
	}

	if (in_own_thread) {
		GThread *thread;

		thread = g_thread_create (run_server_thread, server,
					  TRUE, NULL);
		g_object_set_data (G_OBJECT (server), "thread", thread);
	} else
		soup_server_run_async (server);

	return server;
}
Ejemplo n.º 9
0
static void
dispose (GObject *object)
{
    GCutGLibEventLoopPrivate *priv;

    priv = GCUT_GLIB_EVENT_LOOP_GET_PRIVATE(object);

    if (priv->loop) {
        g_main_loop_unref(priv->loop);
        priv->loop = NULL;
    }

    if (priv->context) {
        g_main_context_unref(priv->context);
        priv->context = NULL;
    }

    G_OBJECT_CLASS(gcut_glib_event_loop_parent_class)->dispose(object);
}
Ejemplo n.º 10
0
Archivo: gpoll.c Proyecto: cosimoc/glib
int
main (int   argc,
      char *argv[])
{
  int result;
  GMainContext *ctx;

  g_test_init (&argc, &argv, NULL);
  init_networking ();
  ctx = g_main_context_new ();

  g_test_add_func ("/gpoll/gpoll", test_gpoll);

  result = g_test_run ();

  g_main_context_unref (ctx);

  return result;
}
Ejemplo n.º 11
0
/*
 * Pass %0 as interval to use an idle function
 */
static void
setup_main_context (GdaConnection *cnc, guint interval, guint *ptr_to_incr)
{
	GMainContext *context;
	GSource *idle;

	context = g_main_context_new ();
	if (interval == 0)
		idle = g_idle_source_new ();
	else
		idle = g_timeout_source_new (interval);
	g_source_set_priority (idle, G_PRIORITY_DEFAULT);
	g_source_attach (idle, context);
	g_source_set_callback (idle, (GSourceFunc) idle_incr, ptr_to_incr, NULL);
	g_source_unref (idle);
	gda_connection_set_main_context (cnc, NULL, context);
	g_signal_connect(cnc, "opened", connection_opened, NULL);
	g_main_context_unref (context);
}
Ejemplo n.º 12
0
static void
gst_bus_set_main_context (GstBus * bus, GMainContext * ctx)
{
  GST_OBJECT_LOCK (bus);

  if (bus->priv->main_context != NULL) {
    g_main_context_unref (bus->priv->main_context);
    bus->priv->main_context = NULL;
  }

  if (ctx != NULL) {
    bus->priv->main_context = g_main_context_ref (ctx);
  }

  GST_DEBUG_OBJECT (bus, "setting main context to %p, GLib default context: %p",
      ctx, g_main_context_default ());

  GST_OBJECT_UNLOCK (bus);
}
Ejemplo n.º 13
0
YapClient::~YapClient()
{
    if(d->msgServerIoSource != NULL) {
        g_source_destroy(d->msgServerIoSource);
        d->msgServerIoSource = NULL;
    }
    if(d->msgServerIoChannel != NULL) {
        g_io_channel_unref(d->msgServerIoChannel);
        d->msgServerIoChannel = NULL;
    }
    if(d->msgServerSocketFd != -1) {
        close(d->msgServerSocketFd);
        d->msgServerSocketFd = -1;
    }

    if (d->msgServerSocketPostfix)
        free(d->msgServerSocketPostfix);

    ::unlink(d->msgServerSocketPath);

    closeMsgSocket();
    closeCmdSocket();

    // We use mainLoop != NULL as a test to tell whether we allocated a loop & context during init().
    // In the case where we're using the default main context, we never allocate a loop.
    if(d->mainLoop != NULL)
    {
        g_main_loop_unref(d->mainLoop);
        g_main_context_unref(d->mainCtxt);
    }

    delete d->msgPacket;
    delete d->cmdPacket;
    delete d->replyPacket;

    delete[] d->msgBuffer;
    delete[] d->cmdBuffer;
    delete[] d->replyBuffer;

    delete d;

    d = NULL;
}
Ejemplo n.º 14
0
static gboolean qio_task_thread_result(gpointer opaque)
{
    struct QIOTaskThreadData *data = opaque;

    trace_qio_task_thread_result(data->task);
    qio_task_complete(data->task);

    if (data->destroy) {
        data->destroy(data->opaque);
    }

    if (data->context) {
        g_main_context_unref(data->context);
    }

    g_free(data);

    return FALSE;
}
Ejemplo n.º 15
0
static void
hrt_event_loop_glib_dispose(GObject *object)
{
    HrtEventLoopGLib *loop;

    loop = HRT_EVENT_LOOP_GLIB(object);

    if (loop->loop) {
        g_main_loop_unref(loop->loop);
        loop->loop = NULL;
    }

    if (loop->context) {
        g_main_context_unref(loop->context);
        loop->context = NULL;
    }

    G_OBJECT_CLASS(hrt_event_loop_glib_parent_class)->dispose(object);
}
Ejemplo n.º 16
0
static void
cockpit_stream_finalize (GObject *object)
{
  CockpitStream *self = COCKPIT_STREAM (object);

  g_assert (self->priv->closed);
  g_assert (!self->priv->in_source);
  g_assert (!self->priv->out_source);

  g_byte_array_unref (self->priv->in_buffer);
  g_queue_free (self->priv->out_queue);
  g_free (self->priv->problem);
  g_free (self->priv->name);

  if (self->priv->context)
    g_main_context_unref (self->priv->context);

  G_OBJECT_CLASS (cockpit_stream_parent_class)->finalize (object);
}
Ejemplo n.º 17
0
static void
shm_reader_set_property (GObject *object, guint property_id,
    const GValue *value, GParamSpec *pspec)
{
  ShmReaderPrivate *priv = SHM_READER (object)->priv;

  switch (property_id)
    {
      case PROP_CONTEXT:
        if (priv->context != NULL)
          g_main_context_unref (priv->context);
        priv->context = g_value_get_pointer (value);
        if (priv->context != NULL)
          g_main_context_ref (priv->context);
        break;
      default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    }
}
Ejemplo n.º 18
0
static void
finalize (GObject *object)
{
	SoupServer *server = SOUP_SERVER (object);
	SoupServerPrivate *priv = SOUP_SERVER_GET_PRIVATE (server);
	GSList *iter;

	if (priv->interface)
		g_object_unref (priv->interface);

	g_free (priv->ssl_cert_file);
	g_free (priv->ssl_key_file);
	if (priv->ssl_creds)
		soup_ssl_free_server_credentials (priv->ssl_creds);

	g_free (priv->server_header);

	if (priv->listen_sock)
		g_object_unref (priv->listen_sock);

	while (priv->client_socks) {
		SoupSocket *sock = priv->client_socks->data;

		soup_socket_disconnect (sock);
		priv->client_socks =
			g_slist_remove (priv->client_socks, sock);
	}

	if (priv->default_handler)
		free_handler (priv->default_handler);
	soup_path_map_free (priv->handlers);

	for (iter = priv->auth_domains; iter; iter = iter->next)
		g_object_unref (iter->data);
	g_slist_free (priv->auth_domains);

	if (priv->loop)
		g_main_loop_unref (priv->loop);
	if (priv->async_context)
		g_main_context_unref (priv->async_context);

	G_OBJECT_CLASS (soup_server_parent_class)->finalize (object);
}
Ejemplo n.º 19
0
static gboolean
gst_gl_window_default_open (GstGLWindow * window, GError ** error)
{
  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);
  }

  return TRUE;
}
Ejemplo n.º 20
0
/* =========================================================================
 * =========================================================================
 */
static void
thread_context_destroy_internal(PmSockThreadContext* const ctx)
{
    PSL_LOG_DEBUG("%s (ctx=%p/%s)", __func__, ctx,
                  PSL_LOG_MAKE_SAFE_STR(ctx->userLabel));

    PSL_ASSERT(ctx);

    g_free(ctx->userLabel);

    if (ctx->gmainCtx) {
        g_main_context_unref(ctx->gmainCtx);
    }

    g_free(ctx);


    PSL_LOG_DEBUGLOW("%s (ctx=%p): LEAVING", __func__, ctx);
}
Ejemplo n.º 21
0
void
swfdec_playback_close (SwfdecPlayback *sound)
{
#define REMOVE_HANDLER_FULL(obj,func,data,count) G_STMT_START {\
  if (g_signal_handlers_disconnect_by_func ((obj), \
	G_CALLBACK (func), (data)) != (count)) { \
    g_assert_not_reached (); \
  } \
} G_STMT_END
#define REMOVE_HANDLER(obj,func,data) REMOVE_HANDLER_FULL (obj, func, data, 1)

  while (sound->streams)
    swfdec_playback_stream_close (sound->streams->data);
  REMOVE_HANDLER (sound->player, advance_before, sound);
  REMOVE_HANDLER (sound->player, audio_added, sound);
  REMOVE_HANDLER (sound->player, audio_removed, sound);
  g_main_context_unref (sound->context);
  g_free (sound);
}
Ejemplo n.º 22
0
static void
dasom_im_finalize (GObject *object)
{
  g_debug (G_STRLOC ": %s", G_STRFUNC);

  DasomIM *im = DASOM_IM (object);

  if (im->sockets_context_source)
  {
    g_source_destroy (im->sockets_context_source);
    g_source_unref   (im->sockets_context_source);
  }

  if (im->default_context_source)
  {
    g_source_destroy (im->default_context_source);
    g_source_unref   (im->default_context_source);
  }

  if (im->connection)
    g_object_unref (im->connection);

  GMutex mutex;

  g_mutex_init (&mutex);
  g_mutex_lock (&mutex);

  if (dasom_im_sockets_context)
  {
    g_main_context_unref (dasom_im_sockets_context);
    dasom_im_sockets_context_ref_count--;

    if (dasom_im_sockets_context_ref_count == 0)
      dasom_im_sockets_context = NULL;
  }

  g_mutex_unlock (&mutex);
  g_slice_free (DasomResult, im->result);
  g_free (im->preedit_string);

  G_OBJECT_CLASS (dasom_im_parent_class)->finalize (object);
}
Ejemplo n.º 23
0
GdaLdapEntry *
gdaprov_ldap_describe_entry (GdaLdapConnection *cnc, const gchar *dn, GError **error)
{
	g_return_val_if_fail (GDA_IS_LDAP_CONNECTION (cnc), NULL);
	g_return_val_if_fail (!dn || (dn && *dn), NULL);

	gda_lockable_lock ((GdaLockable*) cnc); /* CNC LOCK */

	LdapConnectionData *cdata;
        cdata = (LdapConnectionData*) gda_virtual_connection_internal_get_provider_data (GDA_VIRTUAL_CONNECTION (cnc));
        if (!cdata) {
		gda_lockable_unlock ((GdaLockable*) cnc); /* CNC UNLOCK */
                return NULL;
	}

	GdaServerProviderConnectionData *pcdata;
	pcdata = gda_connection_internal_get_provider_data_error ((GdaConnection*) cnc, NULL);

	GdaWorker *worker;
	worker = gda_worker_ref (gda_connection_internal_get_worker (pcdata));

	GMainContext *context;
	context = gda_server_provider_get_real_main_context ((GdaConnection *) cnc);

	WorkerLdapDescrEntryData data;
	data.cnc = cnc;
	data.cdata = cdata;
	data.dn = dn;

	gda_connection_increase_usage ((GdaConnection*) cnc); /* USAGE ++ */
	gpointer retval;
	gda_worker_do_job (worker, context, 0, &retval, NULL,
			   (GdaWorkerFunc) worker_gdaprov_ldap_describe_entry, (gpointer) &data, NULL, NULL, error);
	if (context)
		g_main_context_unref (context);

	gda_connection_decrease_usage ((GdaConnection*) cnc); /* USAGE -- */
	gda_lockable_unlock ((GdaLockable*) cnc); /* CNC UNLOCK */

	gda_worker_unref (worker);
	return (GdaLdapEntry*) retval;
}
Ejemplo n.º 24
0
static gboolean
resolved_proxy (gpointer data)
{
	SoupGNOMEAsyncData *sgad = data;

	sgad->callback (sgad->proxy_uri_resolver, sgad->status,
			sgad->proxy_uri, sgad->user_data);
	g_object_unref (sgad->proxy_uri_resolver);
	if (sgad->uri)
		soup_uri_free (sgad->uri);
	if (sgad->async_context)
		g_main_context_unref (sgad->async_context);
	if (sgad->cancellable)
		g_object_unref (sgad->cancellable);
	if (sgad->proxy_uri)
		soup_uri_free (sgad->proxy_uri);
	g_slice_free (SoupGNOMEAsyncData, sgad);

	return FALSE;
}
Ejemplo n.º 25
0
static void
kms_webrtc_session_finalize (GObject * object)
{
  KmsWebrtcSession *self = KMS_WEBRTC_SESSION (object);

  GST_DEBUG_OBJECT (self, "finalize");

  g_clear_object (&self->agent);
  g_main_context_unref (self->context);
  g_slist_free_full (self->remote_candidates, g_object_unref);

  g_free (self->stun_server_ip);
  g_free (self->turn_url);
  g_free (self->turn_user);
  g_free (self->turn_password);
  g_free (self->turn_address);

  /* chain up */
  G_OBJECT_CLASS (kms_webrtc_session_parent_class)->finalize (object);
}
static void
gst_gl_window_dispmanx_egl_close (GstGLWindow * window)
{
  GstGLWindowDispmanxEGL *window_egl;
  DISPMANX_UPDATE_HANDLE_T dispman_update;

  window_egl = GST_GL_WINDOW_DISPMANX_EGL (window);

  if (window_egl->native.element) {
    dispman_update = vc_dispmanx_update_start (0);
    vc_dispmanx_element_remove (dispman_update, window_egl->native.element);
    vc_dispmanx_update_submit_sync (dispman_update);
  }
  vc_dispmanx_display_close (window_egl->display);

  g_main_loop_unref (window_egl->loop);
  window_egl->loop = NULL;
  g_main_context_unref (window_egl->main_context);
  window_egl->main_context = NULL;
}
Ejemplo n.º 27
0
/** Unset the main context used for the current session run.
 *
 * Must be called right after stopping the session. Note that if the
 * session is stopped asynchronously, the main loop may still be running
 * after the main context has been unset. This is OK as long as no new
 * event sources are created -- the main loop holds its own reference
 * to the main context.
 */
static int unset_main_context(struct sr_session *session)
{
	int ret;

	g_mutex_lock(&session->main_mutex);

	if (session->main_context) {
		g_main_context_unref(session->main_context);
		session->main_context = NULL;
		ret = SR_OK;
	} else {
		/* May happen if the set/unset calls are not matched.
		 */
		sr_err("No main context to unset.");
		ret = SR_ERR;
	}
	g_mutex_unlock(&session->main_mutex);

	return ret;
}
Ejemplo n.º 28
0
static void
gst_video_convert_frame_context_free (GstVideoConvertSampleContext * ctx)
{
  /* Wait until all users of the mutex are done */
  g_mutex_lock (&ctx->mutex);
  g_mutex_unlock (&ctx->mutex);
  g_mutex_clear (&ctx->mutex);
  if (ctx->timeout_source)
    g_source_destroy (ctx->timeout_source);
  //if (ctx->buffer)
  //  gst_buffer_unref (ctx->buffer);
  if (ctx->sample)
    gst_sample_unref (ctx->sample);
  g_main_context_unref (ctx->context);

  gst_element_set_state (ctx->pipeline, GST_STATE_NULL);
  gst_object_unref (ctx->pipeline);

  g_slice_free (GstVideoConvertSampleContext, ctx);
}
Ejemplo n.º 29
0
/* If @context is %NULL, it's own context is used, so component->ctx is always
 * guaranteed to be non-%NULL. */
void
nice_component_set_io_context (NiceComponent *component, GMainContext *context)
{
  g_mutex_lock (&component->io_mutex);

  if (component->ctx != context) {
    if (context == NULL)
      context = g_main_context_ref (component->own_ctx);
    else
      g_main_context_ref (context);

    nice_component_detach_all_sockets (component);
    g_main_context_unref (component->ctx);

    component->ctx = context;
    nice_component_reattach_all_sockets (component);
  }

  g_mutex_unlock (&component->io_mutex);
}
Ejemplo n.º 30
0
static void
g_file_monitor_finalize (GObject *object)
{
  GFileMonitor *monitor;

  monitor = G_FILE_MONITOR (object);

  if (monitor->priv->timeout)
    {
      g_source_destroy (monitor->priv->timeout);
      g_source_unref (monitor->priv->timeout);
    }

  g_hash_table_destroy (monitor->priv->rate_limiter);

  if (monitor->priv->context)
    g_main_context_unref (monitor->priv->context);

  G_OBJECT_CLASS (g_file_monitor_parent_class)->finalize (object);
}