Commit 208a6e81 authored by Philip Withnall's avatar Philip Withnall Committed by Philip Withnall

gmain: Add names to various GSources constructed in GLib

For the purposes of debugging, it is quite useful for every GSource to
have a name set. Ensure that any GSource we construct inside GLib has a
name set. For GSources which are then returned to the caller, this name
can then be overridden with something even more useful by the caller.

Since this data is only used for debugging, avoid doing any allocations
for it; just use static strings.

GNOME/glib#1175
parent cbfa776f
......@@ -648,6 +648,8 @@ g_file_monitor_source_new (gpointer instance,
source = g_source_new (&source_funcs, sizeof (GFileMonitorSource));
fms = (GFileMonitorSource *) source;
g_source_set_name (source, "GFileMonitorSource");
g_mutex_init (&fms->lock);
fms->instance = instance;
fms->pending_changes = g_sequence_new (pending_change_free);
......
......@@ -1975,6 +1975,7 @@ g_task_thread_pool_init (void)
g_thread_pool_set_sort_function (task_pool, g_task_compare_priority, NULL);
task_pool_manager = g_source_new (&trivial_source_funcs, sizeof (GSource));
g_source_set_name (task_pool_manager, "GTask thread pool manager");
g_source_set_callback (task_pool_manager, task_pool_manager_timeout, NULL, NULL);
g_source_set_ready_time (task_pool_manager, -1);
g_source_attach (task_pool_manager,
......
......@@ -5239,6 +5239,68 @@ unref_unix_signal_handler_unlocked (int signum)
}
}
/* Return a const string to avoid allocations. We lose precision in the case the
* @signum is unrecognised, but that’ll do. */
static const gchar *
signum_to_string (int signum)
{
/* See `man 0P signal.h` */
#define SIGNAL(s) \
case (s): \
return ("GUnixSignalSource: " #s);
switch (signum)
{
/* These signals are guaranteed to exist by POSIX. */
SIGNAL (SIGABRT)
SIGNAL (SIGFPE)
SIGNAL (SIGILL)
SIGNAL (SIGINT)
SIGNAL (SIGSEGV)
SIGNAL (SIGTERM)
/* Frustratingly, these are not, and hence for brevity the list is
* incomplete. */
#ifdef SIGALRM
SIGNAL (SIGALRM)
#endif
#ifdef SIGCHLD
SIGNAL (SIGCHLD)
#endif
#ifdef SIGHUP
SIGNAL (SIGHUP)
#endif
#ifdef SIGKILL
SIGNAL (SIGKILL)
#endif
#ifdef SIGPIPE
SIGNAL (SIGPIPE)
#endif
#ifdef SIGQUIT
SIGNAL (SIGQUIT)
#endif
#ifdef SIGSTOP
SIGNAL (SIGSTOP)
#endif
#ifdef SIGUSR1
SIGNAL (SIGUSR1)
#endif
#ifdef SIGUSR2
SIGNAL (SIGUSR2)
#endif
#ifdef SIGPOLL
SIGNAL (SIGPOLL)
#endif
#ifdef SIGPROF
SIGNAL (SIGPROF)
#endif
#ifdef SIGTRAP
SIGNAL (SIGTRAP)
#endif
default:
return "GUnixSignalSource: Unrecognized signal";
}
#undef SIGNAL
}
GSource *
_g_main_create_unix_signal_watch (int signum)
{
......@@ -5251,6 +5313,9 @@ _g_main_create_unix_signal_watch (int signum)
unix_signal_source->signum = signum;
unix_signal_source->pending = FALSE;
/* Set a default name on the source, just in case the caller does not. */
g_source_set_name (source, signum_to_string (signum));
G_LOCK (unix_signal_lock);
ref_unix_signal_handler_unlocked (signum);
unix_signal_watches = g_slist_prepend (unix_signal_watches, unix_signal_source);
......@@ -5379,6 +5444,9 @@ g_child_watch_source_new (GPid pid)
source = g_source_new (&g_child_watch_funcs, sizeof (GChildWatchSource));
child_watch_source = (GChildWatchSource *)source;
/* Set a default name on the source, just in case the caller does not. */
g_source_set_name (source, "GChildWatchSource");
child_watch_source->pid = pid;
#ifdef G_OS_WIN32
......@@ -5565,6 +5633,9 @@ g_idle_source_new (void)
source = g_source_new (&g_idle_funcs, sizeof (GSource));
g_source_set_priority (source, G_PRIORITY_DEFAULT_IDLE);
/* Set a default name on the source, just in case the caller does not. */
g_source_set_name (source, "GIdleSource");
return source;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment