mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-23 10:42:11 +01:00
gmain: Remove dispatching source stack
This stack exists only to answer the question of "what is the currently dispatching source" and is handled in a way that makes it very clear that we don't need to be using a linked list at all... Just store the GSource directly.
This commit is contained in:
parent
236ee65561
commit
183e7c605e
37
glib/gmain.c
37
glib/gmain.c
@ -217,7 +217,7 @@ typedef struct _GMainDispatch GMainDispatch;
|
|||||||
struct _GMainDispatch
|
struct _GMainDispatch
|
||||||
{
|
{
|
||||||
gint depth;
|
gint depth;
|
||||||
GSList *dispatching_sources; /* stack of current sources */
|
GSource *source;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef G_MAIN_POLL_DEBUG
|
#ifdef G_MAIN_POLL_DEBUG
|
||||||
@ -2849,7 +2849,7 @@ GSource *
|
|||||||
g_main_current_source (void)
|
g_main_current_source (void)
|
||||||
{
|
{
|
||||||
GMainDispatch *dispatch = get_dispatch ();
|
GMainDispatch *dispatch = get_dispatch ();
|
||||||
return dispatch->dispatching_sources ? dispatch->dispatching_sources->data : NULL;
|
return dispatch->source;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -3022,7 +3022,7 @@ g_main_dispatch (GMainContext *context)
|
|||||||
gboolean (*dispatch) (GSource *,
|
gboolean (*dispatch) (GSource *,
|
||||||
GSourceFunc,
|
GSourceFunc,
|
||||||
gpointer);
|
gpointer);
|
||||||
GSList current_source_link;
|
GSource *prev_source;
|
||||||
|
|
||||||
dispatch = source->source_funcs->dispatch;
|
dispatch = source->source_funcs->dispatch;
|
||||||
cb_funcs = source->callback_funcs;
|
cb_funcs = source->callback_funcs;
|
||||||
@ -3042,26 +3042,17 @@ g_main_dispatch (GMainContext *context)
|
|||||||
|
|
||||||
UNLOCK_CONTEXT (context);
|
UNLOCK_CONTEXT (context);
|
||||||
|
|
||||||
current->depth++;
|
/* These operations are safe because 'current' is thread-local
|
||||||
/* The on-stack allocation of the GSList is unconventional, but
|
* and not modified from anywhere but this function.
|
||||||
* we know that the lifetime of the link is bounded to this
|
*/
|
||||||
* function as the link is kept in a thread specific list and
|
prev_source = current->source;
|
||||||
* not manipulated outside of this function and its descendants.
|
current->depth++;
|
||||||
* Avoiding the overhead of a g_slist_alloc() is useful as many
|
|
||||||
* applications do little more than dispatch events.
|
need_destroy = !(* dispatch) (source, callback, user_data);
|
||||||
*
|
|
||||||
* This is a performance hack - do not revert to g_slist_prepend()!
|
current->source = prev_source;
|
||||||
*/
|
current->depth--;
|
||||||
current_source_link.data = source;
|
|
||||||
current_source_link.next = current->dispatching_sources;
|
|
||||||
current->dispatching_sources = ¤t_source_link;
|
|
||||||
need_destroy = ! dispatch (source,
|
|
||||||
callback,
|
|
||||||
user_data);
|
|
||||||
g_assert (current->dispatching_sources == ¤t_source_link);
|
|
||||||
current->dispatching_sources = current_source_link.next;
|
|
||||||
current->depth--;
|
|
||||||
|
|
||||||
if (cb_funcs)
|
if (cb_funcs)
|
||||||
cb_funcs->unref (cb_data);
|
cb_funcs->unref (cb_data);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user