g_idle_add()

When a signal is emitted a lot of times, and the processing of the action associated with the signal is expensive, it’s an option to only run the action when the system is idle. Using this function in this manner, this result can be achieved. I got to know this talking to pierlux in #champlain@irc.freenode.net and taking a look at champlain-marker.c from libchamplain. Thanks.

static gboolean scheduled;

static gboolean
run(gpointer user_data)
{
    /* expensive code */
    scheduled = FALSE;
    return FALSE;
}

static void
on_event(GObject * object, gpointer user_data)
{
    if(!scheduled)
    {
        scheduled = TRUE;
        g_idle_add(run, (gpointer) parameter_name);
    }
}

int main(int argc, char **argv)
{
    /* initialization */
    g_signal_connect(object, "event", G_CALLBACK(on_event), NULL);
    /* enter main loop */
}
About these ads

Deixe uma resposta

Preencha os seus dados abaixo ou clique em um ícone para log in:

WordPress.com Logo

Você está comentando usando sua conta WordPress.com. Sair / Mudar )

Imagem do Twitter

Você está comentando usando sua conta Twitter. Sair / Mudar )

Foto do Facebook

Você está comentando usando sua conta Facebook. Sair / Mudar )

Conectando a %s


Seguir

Obtenha todo post novo entregue na sua caixa de entrada.

%d bloggers like this: