Exemplo n.º 1
0
GType
sim_group_alarm_get_type (void)
{
  static GType object_type = 0;
	G_LOCK_DEFINE_STATIC (SimGroupAlarm);
	G_LOCK (SimGroupAlarm); 	
 
  if (!object_type)
  {
    static const GTypeInfo type_info = {
              sizeof (SimGroupAlarmClass),
              NULL,
              NULL,
              (GClassInitFunc) sim_group_alarm_class_init,
              NULL,
              NULL,                       /* class data */
              sizeof (SimGroupAlarm),
              0,                          /* number of pre-allocs */
              (GInstanceInitFunc) sim_group_alarm_instance_init,
              NULL                        /* value table */
    };
   
                                                                                        
                                     
    object_type = g_type_register_static (G_TYPE_OBJECT, "SimGroupAlarm", &type_info, 0);
		
  }
	G_UNLOCK (SimGroupAlarm);
	return object_type;
}
Exemplo n.º 2
0
/**
 * g_thread_pool_new:
 * @func: a function to execute in the threads of the new thread pool
 * @user_data: user data that is handed over to @func every time it
 *     is called
 * @max_threads: the maximal number of threads to execute concurrently
 *     in  the new thread pool, -1 means no limit
 * @exclusive: should this thread pool be exclusive?
 * @error: return location for error, or %NULL
 *
 * This function creates a new thread pool.
 *
 * Whenever you call g_thread_pool_push(), either a new thread is
 * created or an unused one is reused. At most @max_threads threads
 * are running concurrently for this thread pool. @max_threads = -1
 * allows unlimited threads to be created for this thread pool. The
 * newly created or reused thread now executes the function @func
 * with the two arguments. The first one is the parameter to
 * g_thread_pool_push() and the second one is @user_data.
 *
 * The parameter @exclusive determines whether the thread pool owns
 * all threads exclusive or shares them with other thread pools.
 * If @exclusive is %TRUE, @max_threads threads are started
 * immediately and they will run exclusively for this thread pool
 * until it is destroyed by g_thread_pool_free(). If @exclusive is
 * %FALSE, threads are created when needed and shared between all
 * non-exclusive thread pools. This implies that @max_threads may
 * not be -1 for exclusive thread pools. Besides, exclusive thread
 * pools are not affected by g_thread_pool_set_max_idle_time()
 * since their threads are never considered idle and returned to the
 * global pool.
 *
 * @error can be %NULL to ignore errors, or non-%NULL to report
 * errors. An error can only occur when @exclusive is set to %TRUE
 * and not all @max_threads threads could be created.
 * See #GThreadError for possible errors that may occur.
 * Note, even in case of error a valid #GThreadPool is returned.
 *
 * Returns: the new #GThreadPool
 */
GThreadPool *
g_thread_pool_new (GFunc      func,
                   gpointer   user_data,
                   gint       max_threads,
                   gboolean   exclusive,
                   GError   **error)
{
  GRealThreadPool *retval;
  G_LOCK_DEFINE_STATIC (init);

  g_return_val_if_fail (func, NULL);
  g_return_val_if_fail (!exclusive || max_threads != -1, NULL);
  g_return_val_if_fail (max_threads >= -1, NULL);

  retval = g_new (GRealThreadPool, 1);

  retval->pool.func = func;
  retval->pool.user_data = user_data;
  retval->pool.exclusive = exclusive;
  retval->queue = g_async_queue_new ();
  g_cond_init (&retval->cond);
  retval->max_threads = max_threads;
  retval->num_threads = 0;
  retval->running = TRUE;
  retval->immediate = FALSE;
  retval->waiting = FALSE;
  retval->sort_func = NULL;
  retval->sort_user_data = NULL;

  G_LOCK (init);
  if (!unused_thread_queue)
      unused_thread_queue = g_async_queue_new ();
  G_UNLOCK (init);

  if (retval->pool.exclusive)
    {
      g_async_queue_lock (retval->queue);

      while (retval->num_threads < retval->max_threads)
        {
          GError *local_error = NULL;

          if (!g_thread_pool_start_thread (retval, &local_error))
            {
              g_propagate_error (error, local_error);
              break;
            }
        }

      g_async_queue_unlock (retval->queue);
    }

  return (GThreadPool*) retval;
}
Exemplo n.º 3
0
OwrLocalMediaSource *_owr_local_media_source_new_cached(gint device_index, const gchar *name,
    OwrMediaType media_type, OwrSourceType source_type)
{
    static OwrLocalMediaSource *test_sources[2] = { NULL, };
    static GHashTable *sources[2] = { NULL, };
    G_LOCK_DEFINE_STATIC(source_cache);

    OwrLocalMediaSource *ret = NULL;
    gchar *cached_name;
    int i;

    G_LOCK(source_cache);

    if (G_UNLIKELY(sources[0] == NULL)) {
        sources[0] = g_hash_table_new(NULL, NULL);
        sources[1] = g_hash_table_new(NULL, NULL);
    }

    i = media_type == OWR_MEDIA_TYPE_AUDIO ? 0 : 1;

    if (source_type == OWR_SOURCE_TYPE_TEST) {
        if (test_sources[i] == NULL)
            test_sources[i] = _owr_local_media_source_new(device_index, name, media_type, source_type);

        ret = test_sources[i];

    } else if (source_type == OWR_SOURCE_TYPE_CAPTURE) {
        ret = g_hash_table_lookup(sources[i], GINT_TO_POINTER(device_index));

        if (ret) {
            g_object_get(ret, "name", &cached_name, NULL);

            if (!g_str_equal(name, cached_name)) {
                /* Device at this index seems to have changed, throw the old one away */
                g_object_unref(ret);
                ret = NULL;
            }

            g_free(cached_name);
        }

        if (!ret) {
            ret = _owr_local_media_source_new(device_index, name, media_type, source_type);
            g_hash_table_insert(sources[i], GINT_TO_POINTER(device_index), ret);
        }

    } else
        g_assert_not_reached();

    G_UNLOCK (source_cache);

    return g_object_ref(ret);
}
Exemplo n.º 4
0
static gchar *
get_package_directory_from_module (const gchar *module_name)
{
  static GHashTable *module_dirs = NULL;
  G_LOCK_DEFINE_STATIC (module_dirs);
  HMODULE hmodule = NULL;
  gchar *fn;

  G_LOCK (module_dirs);

  if (module_dirs == NULL)
    module_dirs = g_hash_table_new (g_str_hash, g_str_equal);
  
  fn = g_hash_table_lookup (module_dirs, module_name ? module_name : "");
      
  if (fn)
    {
      G_UNLOCK (module_dirs);
      return g_strdup (fn);
    }

  if (module_name)
    {
      wchar_t *wc_module_name = g_utf8_to_utf16 (module_name, -1, NULL, NULL, NULL);
      hmodule = GetModuleHandleW (wc_module_name);
      g_free (wc_module_name);

      if (!hmodule)
	{
	  G_UNLOCK (module_dirs);
	  return NULL;
	}
    }

  fn = g_win32_get_package_installation_directory_of_module (hmodule);

  if (fn == NULL)
    {
      G_UNLOCK (module_dirs);
      return NULL;
    }
  
  g_hash_table_insert (module_dirs, module_name ? g_strdup (module_name) : "", fn);

  G_UNLOCK (module_dirs);

  return g_strdup (fn);
}
Exemplo n.º 5
0
static GType
gst_iir_equalizer_band_get_type (void)
{
#ifdef GSTREAMER_LITE
  static volatile GType type = 0;
  G_LOCK_DEFINE_STATIC(type_init_mutex);
#else // !GSTREAMER_LITE
  static GType type = 0;
#endif // GSTREAMER_LITE

  if (G_UNLIKELY (!type)) {
#ifdef GSTREAMER_LITE
     G_LOCK(type_init_mutex);
     if(!type) // Use double check lock pattern
     {
#endif // GSTREAMER_LITE

    const GTypeInfo type_info = {
      sizeof (GstIirEqualizerBandClass),
      NULL,
      NULL,
      (GClassInitFunc) gst_iir_equalizer_band_class_init,
      NULL,
      NULL,
      sizeof (GstIirEqualizerBand),
      0,
      (GInstanceInitFunc) gst_iir_equalizer_band_init,
    };
    type =
        g_type_register_static (GST_TYPE_OBJECT, "GstIirEqualizerBand",
        &type_info, 0);
#ifdef GSTREAMER_LITE
     }
     G_UNLOCK(type_init_mutex);
#endif // GSTREAMER_LITE
  }
  return (type);
}
Exemplo n.º 6
0
void
vfolder_load_storage (EMailBackend *backend)
{
	/* lock for loading storage, it is safe to call it more than once */
	G_LOCK_DEFINE_STATIC (vfolder_hash);

	CamelService *service;
	const gchar *key;
	const gchar *data_dir;
	const gchar *config_dir;
	gchar *user, *storeuri;
	EFilterRule *rule;
	MailFolderCache *folder_cache;
	EMailSession *session;
	gchar *xmlfile;
	GConfClient *client;

	g_return_if_fail (E_IS_MAIL_BACKEND (backend));

	G_LOCK (vfolder_hash);

	if (vfolder_hash) {
		/* we have already initialized */
		G_UNLOCK (vfolder_hash);
		return;
	}

	vfolder_hash = g_hash_table_new (g_str_hash, g_str_equal);

	G_UNLOCK (vfolder_hash);

	data_dir = mail_session_get_data_dir ();
	config_dir = mail_session_get_config_dir ();
	session = e_mail_backend_get_session (backend);

	/* first, create the vfolder store, and set it up */
	storeuri = g_strdup_printf("vfolder:%s/vfolder", data_dir);
	service = camel_session_add_service (
		CAMEL_SESSION (session), "vfolder",
		storeuri, CAMEL_PROVIDER_STORE, NULL);
	if (service != NULL) {
		camel_service_set_display_name (service, _("Search Folders"));
		em_utils_connect_service_sync (service, NULL, NULL);
	} else {
		g_warning("Cannot open vfolder store - no vfolders available");
		return;
	}

	g_return_if_fail (CAMEL_IS_STORE (service));

	vfolder_store = CAMEL_STORE (service);

	g_signal_connect (
		service, "folder-deleted",
		G_CALLBACK (store_folder_deleted_cb), backend);

	g_signal_connect (
		service, "folder-renamed",
		G_CALLBACK (store_folder_renamed_cb), NULL);

	/* load our rules */
	user = g_build_filename (config_dir, "vfolders.xml", NULL);
	context = em_vfolder_context_new (backend);

	xmlfile = g_build_filename (EVOLUTION_PRIVDATADIR, "vfoldertypes.xml", NULL);
	if (e_rule_context_load ((ERuleContext *) context,
			       xmlfile, user) != 0) {
		g_warning("cannot load vfolders: %s\n", ((ERuleContext *)context)->error);
	}
	g_free (xmlfile);
	g_free (user);

	g_signal_connect (
		context, "rule_added",
		G_CALLBACK (context_rule_added), context);
	g_signal_connect (
		context, "rule_removed",
		G_CALLBACK (context_rule_removed), context);

	/* load store to mail component */
	e_mail_store_add (backend, vfolder_store);

	/* and setup the rules we have */
	rule = NULL;
	while ((rule = e_rule_context_next_rule ((ERuleContext *) context, rule, NULL))) {
		if (rule->name) {
			d(printf("rule added: %s\n", rule->name));
			context_rule_added ((ERuleContext *) context, rule);
		} else {
			d(printf("invalid rule (%p) encountered: rule->name is NULL\n", rule));
		}
	}

	g_free (storeuri);

	/* reenable the feature if required */
	client = gconf_client_get_default ();
	key = "/apps/evolution/mail/display/enable_vfolders";
	if (!gconf_client_get_bool (client, key, NULL))
		gconf_client_set_bool (client, key, TRUE, NULL);
	g_object_unref (client);

	folder_cache = e_mail_session_get_folder_cache (session);

	g_signal_connect (
		folder_cache, "folder-available",
		G_CALLBACK (folder_available_cb), backend);
	g_signal_connect (
		folder_cache, "folder-unavailable",
		G_CALLBACK (folder_unavailable_cb), backend);
	g_signal_connect (
		folder_cache, "folder-deleted",
		G_CALLBACK (folder_deleted_cb), backend);
	g_signal_connect (
		folder_cache, "folder-renamed",
		G_CALLBACK (folder_renamed_cb), NULL);
}