mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 19:36:18 +01:00
GSource: add g_source_set_name, g_source_get_name, g_source_set_name_by_id
These allow applications to give meaningful names to their sources. Source names can then be used for debugging and profiling, for example with systemtap or gdb. https://bugzilla.gnome.org/show_bug.cgi?id=606044
This commit is contained in:
parent
eec66b2f94
commit
e5696c282e
@ -659,6 +659,7 @@ g_source_get_can_recurse
|
||||
g_source_get_context
|
||||
g_source_get_current_time
|
||||
g_source_get_id
|
||||
g_source_get_name
|
||||
g_source_get_priority
|
||||
g_source_new
|
||||
g_source_ref
|
||||
@ -670,6 +671,8 @@ g_source_set_callback
|
||||
g_source_set_callback_indirect
|
||||
g_source_set_can_recurse
|
||||
g_source_set_funcs
|
||||
g_source_set_name
|
||||
g_source_set_name_by_id
|
||||
g_source_is_destroyed
|
||||
g_source_set_priority
|
||||
g_source_unref
|
||||
|
83
glib/gmain.c
83
glib/gmain.c
@ -1271,6 +1271,88 @@ g_source_get_can_recurse (GSource *source)
|
||||
return (source->flags & G_SOURCE_CAN_RECURSE) != 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* g_source_set_name:
|
||||
* @source: a #GSource
|
||||
* @name: debug name for the source
|
||||
*
|
||||
* Sets a name for the source, used in debugging and profiling.
|
||||
* The name defaults to #NULL.
|
||||
*
|
||||
* The source name should describe in a human-readable way
|
||||
* what the source does. For example, "X11 event queue"
|
||||
* or "GTK+ repaint idle handler" or whatever it is.
|
||||
*
|
||||
* It is permitted to call this function multiple times, but is not
|
||||
* recommended due to the potential performance impact. For example,
|
||||
* one could change the name in the "check" function of a #GSourceFuncs
|
||||
* to include details like the event type in the source name.
|
||||
*
|
||||
* Since: 2.26
|
||||
**/
|
||||
void
|
||||
g_source_set_name (GSource *source,
|
||||
const char *name)
|
||||
{
|
||||
g_return_if_fail (source != NULL);
|
||||
|
||||
/* setting back to NULL is allowed, just because it's
|
||||
* weird if get_name can return NULL but you can't
|
||||
* set that.
|
||||
*/
|
||||
|
||||
g_free (source->name);
|
||||
source->name = g_strdup (name);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_source_get_name:
|
||||
* @source: a #GSource
|
||||
*
|
||||
* Gets a name for the source, used in debugging and profiling.
|
||||
* The name may be #NULL if it has never been set with
|
||||
* g_source_set_name().
|
||||
*
|
||||
* Return value: the name of the source
|
||||
* Since: 2.26
|
||||
**/
|
||||
G_CONST_RETURN char*
|
||||
g_source_get_name (GSource *source)
|
||||
{
|
||||
g_return_val_if_fail (source != NULL, NULL);
|
||||
|
||||
return source->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_source_set_name_by_id:
|
||||
* @tag: a #GSource ID
|
||||
* @name: debug name for the source
|
||||
*
|
||||
* Sets the name of a source using its ID.
|
||||
*
|
||||
* This is a convenience utility to set source names from the return
|
||||
* value of g_idle_add(), g_timeout_add(), etc.
|
||||
*
|
||||
* Since: 2.26
|
||||
**/
|
||||
void
|
||||
g_source_set_name_by_id (guint tag,
|
||||
const char *name)
|
||||
{
|
||||
GSource *source;
|
||||
|
||||
g_return_if_fail (tag > 0);
|
||||
|
||||
source = g_main_context_find_source_by_id (NULL, tag);
|
||||
if (source == NULL)
|
||||
return;
|
||||
|
||||
g_source_set_name (source, name);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* g_source_ref:
|
||||
* @source: a #GSource
|
||||
@ -1858,7 +1940,6 @@ g_source_is_destroyed (GSource *source)
|
||||
return SOURCE_DESTROYED (source);
|
||||
}
|
||||
|
||||
|
||||
/* Temporarily remove all this source's file descriptors from the
|
||||
* poll(), so that if data comes available for one of the file descriptors
|
||||
* we don't continually spin in the poll()
|
||||
|
@ -60,7 +60,7 @@ struct _GSource
|
||||
GSource *prev;
|
||||
GSource *next;
|
||||
|
||||
gpointer reserved1;
|
||||
char *name;
|
||||
gpointer reserved2;
|
||||
};
|
||||
|
||||
@ -205,6 +205,13 @@ void g_source_set_funcs (GSource *source,
|
||||
GSourceFuncs *funcs);
|
||||
gboolean g_source_is_destroyed (GSource *source);
|
||||
|
||||
void g_source_set_name (GSource *source,
|
||||
const char *name);
|
||||
G_CONST_RETURN char* g_source_get_name (GSource *source);
|
||||
void g_source_set_name_by_id (guint tag,
|
||||
const char *name);
|
||||
|
||||
|
||||
/* Used to implement g_source_connect_closure and internally*/
|
||||
void g_source_set_callback_indirect (GSource *source,
|
||||
gpointer callback_data,
|
||||
|
Loading…
Reference in New Issue
Block a user