tags:

views:

55

answers:

1

I need to modify a GLib's time-out interval while it is in execution. Is that possible? I took a look to the source code and it seems possible to me, but is required use some non-public functions from GLib internals. Should I reimplement GTimeoutSource or there are a way to do it?

A: 

In your timeout function, you could re-add the function with the new timeout interval and then return FALSE to remove the timeout with the old interval:

gboolean 
my_timeout_function(gpointer data)
{
    // do stuff
    // ...

    if(need_to_change_interval)
    {
        g_timeout_add(new_interval, (GSourceFunc)my_timeout_function, data);
        return FALSE;
    }
    return TRUE;
}
ptomato
Yeah, this is what I thought but I was looking for a better solution because g_timeout_add creates a new GSource (GTimeoutSource, in fact) and returning FALSE destroys the current GSource you are using when you really want just to modify the interval, not destroy and recreate the whole GTimeoutSource.
Matachana
I don't think it will be a noticeable performance problem. The Glib developers usually have a good reason when they don't expose an internal in their API.
ptomato