[gnome-builder] task: add helper to list active tasks from debugger
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] task: add helper to list active tasks from debugger
- Date: Wed, 11 Apr 2018 09:24:42 +0000 (UTC)
commit 261faf2aa608dc2e5c2ffa14c633544779cacd0d
Author: Christian Hergert <chergert redhat com>
Date: Wed Apr 11 02:24:56 2018 -0700
task: add helper to list active tasks from debugger
src/libide/threading/ide-task.c | 38 ++++++++++++++++++++++++++++++++++++++
src/libide/threading/ide-task.h | 2 ++
2 files changed, 40 insertions(+)
---
diff --git a/src/libide/threading/ide-task.c b/src/libide/threading/ide-task.c
index aee1155bf..559d73708 100644
--- a/src/libide/threading/ide-task.c
+++ b/src/libide/threading/ide-task.c
@@ -142,6 +142,13 @@ typedef struct
typedef struct
{
+ /*
+ * @global_link is used to store a pointer to the task in the global
+ * queue during the lifetime of the task. This is a debugging feature
+ * so that we can dump the list of active tasks from the debugger.
+ */
+ GList global_link;
+
/*
* Controls access to our private data. We only access structure
* data while holding this mutex to ensure that we have consistency
@@ -319,6 +326,9 @@ enum {
};
static GParamSpec *properties [N_PROPS];
+static GQueue global_task_list = G_QUEUE_INIT;
+
+G_LOCK_DEFINE (global_task_list);
static void
ide_task_cancel_free (IdeTaskCancel *cancel)
@@ -574,6 +584,10 @@ ide_task_finalize (GObject *object)
IdeTask *self = (IdeTask *)object;
IdeTaskPrivate *priv = ide_task_get_instance_private (self);
+ G_LOCK (global_task_list);
+ g_queue_unlink (&global_task_list, &priv->global_link);
+ G_UNLOCK (global_task_list);
+
if (!priv->return_called)
g_critical ("%s [%s] finalized before completing",
G_OBJECT_TYPE_NAME (self),
@@ -664,6 +678,11 @@ ide_task_init (IdeTask *self)
priv->release_on_propagate = TRUE;
priv->priority = G_PRIORITY_DEFAULT;
priv->main_context = g_main_context_ref_thread_default ();
+ priv->global_link.data = self;
+
+ G_LOCK (global_task_list);
+ g_queue_push_tail_link (&global_task_list, &priv->global_link);
+ G_UNLOCK (global_task_list);
}
/**
@@ -2032,3 +2051,22 @@ async_result_init_iface (GAsyncResultIface *iface)
iface->get_source_object = ide_task_get_source_object_full;
iface->is_tagged = ide_task_is_tagged;
}
+
+void
+ide_dump_tasks (void)
+{
+ guint i = 0;
+
+ G_LOCK (global_task_list);
+
+ for (const GList *iter = global_task_list.head; iter; iter = iter->next)
+ {
+ IdeTask *self = iter->data;
+ IdeTaskPrivate *priv = ide_task_get_instance_private (self);
+
+ g_printerr ("[%02d]: %s %s\n", i++, priv->name,
+ priv->completed ? "completed" : "");
+ }
+
+ G_UNLOCK (global_task_list);
+}
diff --git a/src/libide/threading/ide-task.h b/src/libide/threading/ide-task.h
index b0e383d30..1778dae4b 100644
--- a/src/libide/threading/ide-task.h
+++ b/src/libide/threading/ide-task.h
@@ -162,6 +162,8 @@ void ide_task_report_new_error (gpointer source_o
gint code,
const gchar *format,
...) G_GNUC_PRINTF (7, 8);
+IDE_AVAILABLE_IN_3_30
+void ide_dump_tasks (void);
#ifdef __GNUC__
# define ide_task_new(self, cancellable, callback, user_data) \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]