return (source_a->priority < source_b->priority) ? -1 : 1;
}
-/* HOLDS: main_loop_lock */
+/* HOLDS: main_loop lock */
static void
g_source_destroy_func (GHookList *hook_list,
GHook *hook)
G_LOCK (main_loop);
if (!source_list.is_setup)
- g_hook_list_init (&source_list, sizeof(GSource));
+ {
+ g_hook_list_init (&source_list, sizeof (GSource));
- source_list.hook_destroy = g_source_destroy_func;
+ source_list.hook_destroy = G_HOOK_DEFERRED_DESTROY;
+ source_list.hook_free = g_source_destroy_func;
+ }
- source = (GSource *)g_hook_alloc (&source_list);
+ source = (GSource*) g_hook_alloc (&source_list);
source->priority = priority;
source->source_data = source_data;
source->hook.func = funcs;
continue;
}
- in_check_or_prepare++;
- if (hook->flags & G_SOURCE_READY ||
- ((GSourceFuncs *) hook->func)->prepare (source->source_data,
- ¤t_time,
- &source_timeout))
+ if (!(hook->flags & G_SOURCE_READY))
{
+ gboolean (*prepare) (gpointer source_data,
+ GTimeVal *current_time,
+ gint *timeout);
+
+ prepare = ((GSourceFuncs *) hook->func)->prepare;
+ in_check_or_prepare++;
+ G_UNLOCK (main_loop);
+
+ if ((*prepare) (source->source_data, ¤t_time, &source_timeout))
+ hook->flags |= G_SOURCE_READY;
+
+ G_LOCK (main_loop);
in_check_or_prepare--;
+ }
+
+ if (hook->flags & G_SOURCE_READY)
+ {
if (!dispatch)
{
- hook->flags |= G_SOURCE_READY;
g_hook_unref (&source_list, hook);
G_UNLOCK (main_loop);
}
else
{
- hook->flags |= G_SOURCE_READY;
n_ready++;
current_priority = source->priority;
timeout = 0;
}
}
- else
- in_check_or_prepare--;
if (source_timeout >= 0)
{
continue;
}
- in_check_or_prepare++;
- if (hook->flags & G_SOURCE_READY ||
- ((GSourceFuncs *) hook->func)->check (source->source_data,
- ¤t_time))
+ if (!(hook->flags & G_SOURCE_READY))
{
+ gboolean (*check) (gpointer source_data,
+ GTimeVal *current_time);
+
+ check = ((GSourceFuncs *) hook->func)->check;
+ in_check_or_prepare++;
+ G_UNLOCK (main_loop);
+
+ if ((*check) (source->source_data, ¤t_time))
+ hook->flags |= G_SOURCE_READY;
+
+ G_LOCK (main_loop);
in_check_or_prepare--;
+ }
+
+ if (hook->flags & G_SOURCE_READY)
+ {
if (dispatch)
{
hook->flags &= ~G_SOURCE_READY;
return TRUE;
}
}
- else
- in_check_or_prepare--;
hook = g_hook_next_valid (&source_list, hook, TRUE);
}
if (in_check_or_prepare)
{
g_warning ("g_main_iteration(): called recursively from within a source's check() or "
- "prepare() member, iteration not possible");
+ "prepare() member or from a second thread, iteration not possible");
return FALSE;
}
else
if (in_check_or_prepare)
{
g_warning ("g_main_run(): called recursively from within a source's check() or "
- "prepare() member, iteration not possible");
+ "prepare() member or from a second thread, iteration not possible");
return;
}
{
GTimeoutData *data = source_data;
- if (data->callback(user_data))
+ if (data->callback (user_data))
{
guint seconds = data->interval / 1000;
guint msecs = data->interval - seconds * 1000;