gtask: Add a g_task_set_name() method

Similarly to g_source_set_name(), this sets a name on a GTask for
debugging and profiling. Importantly, this name is propagated to the
GSource for idle callbacks for the GTask, ending the glorious reign of
`[gio] complete_in_idle_cb`.

The name can be queried using g_task_get_name(). Locking is avoided by
only allowing the name to be set before the GTask is used from another
thread.

Includes tests.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
This commit is contained in:
Philip Withnall
2018-10-07 17:37:58 +01:00
parent f65adb48e1
commit e89128a935
4 changed files with 109 additions and 1 deletions

View File

@@ -74,6 +74,9 @@ void g_task_set_check_cancellable (GTask *task,
GLIB_AVAILABLE_IN_2_36
void g_task_set_source_tag (GTask *task,
gpointer source_tag);
GLIB_AVAILABLE_IN_2_60
void g_task_set_name (GTask *task,
const gchar *name);
GLIB_AVAILABLE_IN_2_36
gpointer g_task_get_source_object (GTask *task);
@@ -89,6 +92,8 @@ GLIB_AVAILABLE_IN_2_36
gboolean g_task_get_check_cancellable (GTask *task);
GLIB_AVAILABLE_IN_2_36
gpointer g_task_get_source_tag (GTask *task);
GLIB_AVAILABLE_IN_2_60
const gchar *g_task_get_name (GTask *task);
GLIB_AVAILABLE_IN_2_36
gboolean g_task_is_valid (gpointer result,