[gnome-builder/wip/chergert/clang] task: allow different priority for thread vs completion
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/chergert/clang] task: allow different priority for thread vs completion
- Date: Tue, 1 May 2018 21:32:15 +0000 (UTC)
commit 9ec5f4503f4bd562d9c87042433da9e76c0632b5
Author: Christian Hergert <chergert redhat com>
Date: Mon Apr 30 18:15:28 2018 -0700
task: allow different priority for thread vs completion
We might want a higher priority for a thread worker than we do
for the completion within the main context. We also default this
to be lower than various gtk main loop processing.
src/libide/threading/ide-task.c | 44 +++++++++++++++++++++++++++++++++++++----
src/libide/threading/ide-task.h | 5 +++++
2 files changed, 45 insertions(+), 4 deletions(-)
---
diff --git a/src/libide/threading/ide-task.c b/src/libide/threading/ide-task.c
index 474fb92c3..fe295787e 100644
--- a/src/libide/threading/ide-task.c
+++ b/src/libide/threading/ide-task.c
@@ -112,7 +112,7 @@ typedef struct
/*
* Priority for our GSource attached to @main_context.
*/
- gint priority;
+ gint complete_priority;
/*
* The actual result information, broken down by result @type.
@@ -242,6 +242,13 @@ typedef struct
*/
gint priority;
+ /*
+ * The priority for completing the result back on the main context. This
+ * defaults to a value lower than gtk redraw priority to ensure that gtk
+ * has higher priority than task completion.
+ */
+ gint complete_priority;
+
/*
* While we're waiting for our return callback, this is set to our
* source id. We use that to know we need to block on the main loop
@@ -489,7 +496,7 @@ ide_task_complete (IdeTaskResult *result)
g_source_set_name (source, "[ide-task] complete result");
g_source_set_ready_time (source, -1);
g_source_set_callback (source, ide_task_return_cb, result, NULL);
- g_source_set_priority (source, result->priority);
+ g_source_set_priority (source, result->complete_priority);
ret = g_source_attach (source, result->main_context);
g_source_unref (source);
@@ -677,6 +684,7 @@ ide_task_init (IdeTask *self)
priv->check_cancellable = TRUE;
priv->release_on_propagate = TRUE;
priv->priority = G_PRIORITY_DEFAULT;
+ priv->complete_priority = GDK_PRIORITY_REDRAW + 1;
priv->main_context = g_main_context_ref_thread_default ();
priv->global_link.data = self;
@@ -838,6 +846,34 @@ ide_task_set_priority (IdeTask *self,
g_mutex_unlock (&priv->mutex);
}
+gint
+ide_task_get_complete_priority (IdeTask *self)
+{
+ IdeTaskPrivate *priv = ide_task_get_instance_private (self);
+ gint ret;
+
+ g_return_val_if_fail (IDE_IS_TASK (self), 0);
+
+ g_mutex_lock (&priv->mutex);
+ ret = priv->complete_priority;
+ g_mutex_unlock (&priv->mutex);
+
+ return ret;
+}
+
+void
+ide_task_set_complete_priority (IdeTask *self,
+ gint complete_priority)
+{
+ IdeTaskPrivate *priv = ide_task_get_instance_private (self);
+
+ g_return_if_fail (IDE_IS_TASK (self));
+
+ g_mutex_lock (&priv->mutex);
+ priv->complete_priority = complete_priority;
+ g_mutex_unlock (&priv->mutex);
+}
+
/**
* ide_task_get_cancellable:
* @self: a #IdeTask
@@ -877,7 +913,7 @@ ide_task_deliver_result (IdeTask *self,
result->task = g_object_ref (self);
result->main_context = g_main_context_ref (priv->main_context);
- result->priority = priv->priority;
+ result->complete_priority = priv->complete_priority;
g_mutex_lock (&priv->mutex);
@@ -1065,7 +1101,7 @@ ide_task_return (IdeTask *self,
result->task = g_object_ref (self);
result->main_context = g_main_context_ref (priv->main_context);
- result->priority = priv->priority;
+ result->complete_priority = priv->complete_priority;
/* We can queue the result immediately if we're not being called
* while we're inside of a ide_task_run_in_thread() callback. Otherwise,
diff --git a/src/libide/threading/ide-task.h b/src/libide/threading/ide-task.h
index 1778dae4b..c02c76fb3 100644
--- a/src/libide/threading/ide-task.h
+++ b/src/libide/threading/ide-task.h
@@ -70,6 +70,8 @@ const gchar *ide_task_get_name (IdeTask *self);
IDE_AVAILABLE_IN_3_30
gint ide_task_get_priority (IdeTask *self);
IDE_AVAILABLE_IN_3_30
+gint ide_task_get_complete_priority (IdeTask *self);
+IDE_AVAILABLE_IN_3_30
gpointer ide_task_get_source_object (IdeTask *self);
IDE_AVAILABLE_IN_3_30
gpointer ide_task_get_source_tag (IdeTask *self);
@@ -141,6 +143,9 @@ IDE_AVAILABLE_IN_3_30
void ide_task_set_priority (IdeTask *self,
gint priority);
IDE_AVAILABLE_IN_3_30
+void ide_task_set_complete_priority (IdeTask *self,
+ gint complete_priority);
+IDE_AVAILABLE_IN_3_30
void ide_task_set_release_on_propagate (IdeTask *self,
gboolean release_on_propagate);
IDE_AVAILABLE_IN_3_30
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]