[gnome-online-accounts/gnome-3-16] daemon: Prioritize D-Bus calls over internal ones



commit ca645e8ae8e62ce7bee376fb1380c8ddc0cf9e50
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed Nov 25 18:38:36 2015 +0100

    daemon: Prioritize D-Bus calls over internal ones
    
    Unlike internal calls, EnsureCredentials calls received over D-Bus can
    time out if we don't handle them in time. Also, D-Bus calls are likely
    to originate from real world applications, while the internal calls are
    a house keeping activity triggered by potential network changes.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=751524

 src/daemon/goadaemon.c |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)
---
diff --git a/src/daemon/goadaemon.c b/src/daemon/goadaemon.c
index 587c12f..1b21206 100644
--- a/src/daemon/goadaemon.c
+++ b/src/daemon/goadaemon.c
@@ -1234,6 +1234,20 @@ ensure_credentials_queue_collector (GObject *source_object, GAsyncResult *res, g
   g_object_unref (task);
 }
 
+static gint
+ensure_credentials_queue_sort (gconstpointer a, gconstpointer b, gpointer user_data)
+{
+  GTask *task_a = G_TASK (a);
+  GTask *task_b = G_TASK (b);
+  gint priority_a;
+  gint priority_b;
+
+  priority_a = g_task_get_priority (task_a);
+  priority_b = g_task_get_priority (task_b);
+
+  return priority_a - priority_b;
+}
+
 static void
 ensure_credentials_queue_check (GoaDaemon *self)
 {
@@ -1250,6 +1264,8 @@ ensure_credentials_queue_check (GoaDaemon *self)
   if (self->ensure_credentials_queue->length == 0)
     goto out;
 
+  g_queue_sort (self->ensure_credentials_queue, ensure_credentials_queue_sort, NULL);
+
   task = G_TASK (g_queue_peek_head (self->ensure_credentials_queue));
   self->ensure_credentials_running = TRUE;
 
@@ -1308,6 +1324,7 @@ on_account_handle_ensure_credentials (GoaAccount            *account,
   data = ensure_data_new (object, invocation);
 
   task = g_task_new (self, NULL, NULL, NULL);
+  g_task_set_priority (task, G_PRIORITY_HIGH);
   g_task_set_task_data (task, data, (GDestroyNotify) ensure_data_unref);
   g_queue_push_tail (self->ensure_credentials_queue, g_object_ref (task));
 
@@ -1360,6 +1377,7 @@ goa_daemon_check_credentials (GoaDaemon *self)
       data = ensure_data_new (object, NULL);
 
       task = g_task_new (self, NULL, NULL, NULL);
+      g_task_set_priority (task, G_PRIORITY_LOW);
       g_task_set_task_data (task, data, (GDestroyNotify) ensure_data_unref);
       g_queue_push_tail (self->ensure_credentials_queue, g_object_ref (task));
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]