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 */
}