summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2016-01-25 15:53:31 +0100
committerMilan Crha <mcrha@redhat.com>2016-01-25 15:57:51 +0100
commit3153138001f678c00bd299852ed94c92ebdda431 (patch)
treed7d6ea9ddedcb5f6fa2ad34590a8b3b792de0c2f
parentc85a6f125ae9bcab916c8d1771f623e46f6da6ff (diff)
downloadevolution-data-server-3153138001f678c00bd299852ed94c92ebdda431.tar.gz
[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.
-rw-r--r--camel/providers/imapx/camel-imapx-conn-manager.c22
-rw-r--r--camel/providers/imapx/camel-imapx-server.c4
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 b756d5c58..052080ef8 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 582d6a4da..b28c4be38 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));
}