current_time in main loop



hey owen,

i just came across the current_time values you pass in to glib main loop
sources in prepare(), check() and dispatch().
while current_time contains a reasonably valid value for prepare() (minus
the delay that occoured from previoud prepare() calls), it is more or
less bogus (too old) for check() and dispatch():

[stripped irrelevant code portions]
static void
g_main_dispatch (GTimeVal *current_time)
{
  while (pending_dispatches != NULL)
    {
      GSource *source = pending_dispatches->data;
      GSList *tmp_list;

      tmp_list = pending_dispatches;
      pending_dispatches = g_slist_remove_link (pending_dispatches, pending_dispatches);
      g_slist_free_1 (tmp_list);

      dispatch (source->source_data, current_time, source->hook.data);
    }
}
static gboolean
g_main_iterate (gboolean block,
                gboolean dispatch)
{
  GTimeVal current_time  ={ 0, 0 };

  g_get_current_time (&current_time);

  hook = g_hook_first_valid (&source_list, TRUE);
  while (hook)
    {
      (*prepare) (source->source_data, &current_time, &source_timeout, source->hook.data);
      hook = g_hook_next_valid (&source_list, hook, TRUE);
    }

  g_main_poll (timeout, n_ready > 0, current_priority);

  hook = g_hook_first_valid (&source_list, TRUE);
  while (hook)
    {
      (*check) (source->source_data, &current_time, source->hook.data);
      hook = g_hook_next_valid (&source_list, hook, TRUE);
    }

  if (pending_dispatches)
    g_main_dispatch (&current_time);
}

at least directly after poll() we should refetch current_time, and since
dispatching can be quite time consuming for some sources, i think we should
also refetch it after a source has been dispatched.
with what we currently have, all current_time values only refer to the one
moment when we started out with preparing the sources, and i don't really
see how that would be usefull (in check() and dispatch()).
if, for *some* reason that is not yet aparent to me, you actually mean to
pass around time_when_loop_iteration_started, then we have to at least
rename current_time to something different.

whish you and your family a merry christmass, btw ;)

---
ciaoTJ



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