guint 
g_source_add (gint           priority,
	      gboolean       can_recurse,
	      GSourceFuncs  *funcs,
	      gpointer       source_data, 
	      gpointer       user_data,
	      GDestroyNotify notify)
{
  guint return_val;
  GSource *source;

  G_LOCK (main_loop);

  if (!source_list.is_setup)
    {
      g_hook_list_init (&source_list, sizeof (GSource));

      source_list.hook_destroy = G_HOOK_DEFERRED_DESTROY;
      source_list.hook_free = g_source_destroy_func;
    }

  source = (GSource*) g_hook_alloc (&source_list);
  source->priority = priority;
  source->source_data = source_data;
  source->hook.func = funcs;
  source->hook.data = user_data;
  source->hook.destroy = notify;
  
  g_hook_insert_sorted (&source_list, 
			(GHook *)source, 
			g_source_compare);

  if (can_recurse)
    source->hook.flags |= G_SOURCE_CAN_RECURSE;

  return_val = source->hook.hook_id;

#ifdef G_THREADS_ENABLED
  /* Now wake up the main loop if it is waiting in the poll() */
  g_main_wakeup ();
#endif

  G_UNLOCK (main_loop);

  return return_val;
}
Beispiel #2
0
void
gth_hook_add_callback (const char *name,
		       int         sort_order,
		       GCallback   callback,
		       gpointer    data)
{
	GthHook *hook;
	GHook   *function;

	hook = GET_HOOK (name);

	function = g_hook_alloc (hook->list);
	function->func = callback;
	function->data = data;
	function->destroy = NULL;
	GTH_HOOK_CALLBACK (function)->sort_order = sort_order;

	g_hook_insert_sorted (hook->list, function, hook_compare_func);
}
Beispiel #3
0
/**
 * Add an InitFunc to the hooklist with the name 'name'
 */
void
NamedInitFuncAdd(const char *name, InitFuncPriority priority, InitFunc func, const char *func_name)
{
    if (!namedInitFuncs)
    {
        namedInitFuncs = g_hash_table_new(g_str_hash, g_str_equal);
        if (!namedInitFuncs)
        {
            g_error("%s: Out of memory on initialization.\n", __FUNCTION__);
            abort();
        }
    }

    if (g_hash_table_lookup(namedInitFuncs, (gconstpointer)name) == NULL)
    {
        GNamedHookList *namedHookList = malloc(sizeof (GNamedHookList));
        if (!namedHookList)
        {
            g_error("%s: Out of memory on initialization.\n", __FUNCTION__);
            abort();
        }
        g_hook_list_init((GHookList*)namedHookList, sizeof(GPrioritizedHook));

        namedHookList->name = name;
       
        g_hash_table_insert(namedInitFuncs, (char*)name, namedHookList);
    }

    GHookList *hookList = (GHookList*)g_hash_table_lookup(namedInitFuncs, (gconstpointer)name);

    GPrioritizedHook *hook = (GPrioritizedHook*)g_hook_alloc(hookList);

    hook->base.data = func;
    hook->base.func = HookInit;
    hook->priority  = priority;
    hook->func_name = func_name;

    g_hook_insert_sorted(hookList, (GHook*)hook, GPrioritizedHookCompare);
}