[evolution-data-server/gnome-3-18] [IMAPx] Connection could be used multiple times at once in certain cases



commit 3153138001f678c00bd299852ed94c92ebdda431
Author: Milan Crha <mcrha redhat com>
Date:   Mon Jan 25 15:53:31 2016 +0100

    [IMAPx] Connection could be used multiple times at once in certain cases
    
    Sometimes, with a good thread interleaving, one connection could be
    used by multiple threads at once, this resulted in runtime warnings like:
    > Starting command ... while still processing ...
    which is a safety check for these cases. This change makes sure that
    the connections are reserved for one thread only.

 camel/providers/imapx/camel-imapx-conn-manager.c |   22 ++++++++++++++++++++--
 camel/providers/imapx/camel-imapx-server.c       |    4 ++--
 2 files changed, 22 insertions(+), 4 deletions(-)
---
diff --git a/camel/providers/imapx/camel-imapx-conn-manager.c 
b/camel/providers/imapx/camel-imapx-conn-manager.c
index b756d5c..052080e 100644
--- a/camel/providers/imapx/camel-imapx-conn-manager.c
+++ b/camel/providers/imapx/camel-imapx-conn-manager.c
@@ -216,6 +216,25 @@ connection_info_unref (ConnectionInfo *cinfo)
 }
 
 static gboolean
+connection_info_try_reserve (ConnectionInfo *cinfo)
+{
+       gboolean reserved = FALSE;
+
+       g_return_val_if_fail (cinfo != NULL, FALSE);
+
+       g_mutex_lock (&cinfo->lock);
+
+       if (!cinfo->busy) {
+               cinfo->busy = TRUE;
+               reserved = TRUE;
+       }
+
+       g_mutex_unlock (&cinfo->lock);
+
+       return reserved;
+}
+
+static gboolean
 connection_info_get_busy (ConnectionInfo *cinfo)
 {
        gboolean busy;
@@ -845,9 +864,8 @@ camel_imapx_conn_manager_ref_connection (CamelIMAPXConnManager *conn_man,
                        for (link = conn_man->priv->connections; link; link = g_list_next (link)) {
                                ConnectionInfo *candidate = link->data;
 
-                               if (candidate && !connection_info_get_busy (candidate)) {
+                               if (candidate && connection_info_try_reserve (candidate)) {
                                        cinfo = connection_info_ref (candidate);
-                                       connection_info_set_busy (cinfo, TRUE);
                                        break;
                                }
                        }
diff --git a/camel/providers/imapx/camel-imapx-server.c b/camel/providers/imapx/camel-imapx-server.c
index 582d6a4..b28c4be 100644
--- a/camel/providers/imapx/camel-imapx-server.c
+++ b/camel/providers/imapx/camel-imapx-server.c
@@ -3614,8 +3614,8 @@ camel_imapx_server_process_command_sync (CamelIMAPXServer *is,
        COMMAND_LOCK (is);
 
        if (is->priv->current_command != NULL) {
-               g_warning ("%s: Starting command %p (%s) while still processing %p (%s)", G_STRFUNC,
-                       ic, camel_imapx_job_get_kind_name (ic->job_kind),
+               g_warning ("%s: [%c] %p: Starting command %p (%s) while still processing %p (%s)", G_STRFUNC,
+                       is->priv->tagprefix, is, ic, camel_imapx_job_get_kind_name (ic->job_kind),
                        is->priv->current_command, camel_imapx_job_get_kind_name 
(is->priv->current_command->job_kind));
        }
 


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