Re: g_timeout_add to a context



On Thu, 2007-06-07 at 11:11 +0000, Emilio Monti wrote:
> Hi,
> Is there any good motivation for the lack of the GMainContext argument
> from "g_timeout_add" ?

 A) GMainContext didn't exist when g_timeout_add() was created
 B) It's not the normal case

> Is there any counter-indication for the addition of a function like
> the following to "gmain" ?
> 
> -----------------------------------------
> guint g_timeout_add_to_context(guint interval, GSourceFunc function,
> gpointer data, GMainContext *context) {
>     GSource *source;
>     guint id;
> 
>     g_return_val_if_fail(function != NULL, 0);
>     source = g_timeout_source_new(interval);
>     g_source_set_callback(source, function, data, NULL);
>     id = g_source_attach(source, context);
>     g_source_unref(source);
> 
>     return id;
> }
> -----------------------------------------
> 
> Does make any sense to add a Bugzilla feature request for the addition
> of this function ?
>
> In my opinion, it is quite useful in multi-threaded applications where
> different threads have to use a separate main loop.

I think you should just put the above function (called something other
than g_...) into your own application. It's not complex and uses nothing
but public API.

When I added GMainContext, the idea of a full set of new variants like:

guint g_io_add_watch_full_with_context (GMainContext    *context,
                                        GIOChannel      *channel,
		                        gint             priority,
                                        GIOCondition     condition,
                                        GIOFunc          func,
                                        gpointer         user_data,
                                        GDestroyNotify   notify);

Didn't appeal. (And you can through g_source_set_closure() into the mix 
too and get even more possible variants.)

Instead the idea was to create an API that allowed for combinatorial
possibilities without combinatorial numbers of entry points, and let people
decide for themselves what, if any, extra convenience functions would be
useful.

					- Owen





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]