[evolution-data-server/evolution-data-server-3-12] Bug 739610 - [IMAPx] Prevent running FETCH and STORE at the same time



commit 8558003ee2c4fd75f289c7a0289f739006555a42
Author: Milan Crha <mcrha redhat com>
Date:   Wed Nov 12 08:19:09 2014 +0100

    Bug 739610 - [IMAPx] Prevent running FETCH and STORE at the same time

 camel/providers/imapx/camel-imapx-mailbox.c |   20 ++++++++++++++++++++
 camel/providers/imapx/camel-imapx-mailbox.h |    5 +++++
 camel/providers/imapx/camel-imapx-server.c  |   12 ++++++++++++
 3 files changed, 37 insertions(+), 0 deletions(-)
---
diff --git a/camel/providers/imapx/camel-imapx-mailbox.c b/camel/providers/imapx/camel-imapx-mailbox.c
index 9404b3a..fbdad1e 100644
--- a/camel/providers/imapx/camel-imapx-mailbox.c
+++ b/camel/providers/imapx/camel-imapx-mailbox.c
@@ -49,6 +49,7 @@ struct _CamelIMAPXMailboxPrivate {
        guint32 permanentflags;
 
        GMutex property_lock;
+       GRecMutex update_lock;
 
        /* Protected by the "property_lock". */
        GHashTable *attributes;
@@ -95,6 +96,7 @@ imapx_mailbox_finalize (GObject *object)
        g_free (priv->name);
 
        g_mutex_clear (&priv->property_lock);
+       g_rec_mutex_clear (&priv->update_lock);
        g_hash_table_destroy (priv->attributes);
        g_sequence_free (priv->message_map);
        g_strfreev (priv->quota_roots);
@@ -121,6 +123,7 @@ camel_imapx_mailbox_init (CamelIMAPXMailbox *mailbox)
        mailbox->priv = CAMEL_IMAPX_MAILBOX_GET_PRIVATE (mailbox);
 
        g_mutex_init (&mailbox->priv->property_lock);
+       g_rec_mutex_init (&mailbox->priv->update_lock);
        mailbox->priv->message_map = g_sequence_new (NULL);
        mailbox->priv->permanentflags = ~0;
 }
@@ -1145,3 +1148,20 @@ camel_imapx_mailbox_handle_status_response (CamelIMAPXMailbox *mailbox,
                mailbox->priv->highestmodseq = value64;
 }
 
+/* Prevents running FETCH and STORE at the same time for the given mailbox */
+void
+camel_imapx_mailbox_lock_update (CamelIMAPXMailbox *mailbox)
+{
+       g_return_if_fail (CAMEL_IS_IMAPX_MAILBOX (mailbox));
+
+       g_rec_mutex_lock (&mailbox->priv->update_lock);
+}
+
+/* Prevents running FETCH and STORE at the same time for the given mailbox */
+void
+camel_imapx_mailbox_unlock_update (CamelIMAPXMailbox *mailbox)
+{
+       g_return_if_fail (CAMEL_IS_IMAPX_MAILBOX (mailbox));
+
+       g_rec_mutex_unlock (&mailbox->priv->update_lock);
+}
diff --git a/camel/providers/imapx/camel-imapx-mailbox.h b/camel/providers/imapx/camel-imapx-mailbox.h
index d49be6d..e89010c 100644
--- a/camel/providers/imapx/camel-imapx-mailbox.h
+++ b/camel/providers/imapx/camel-imapx-mailbox.h
@@ -162,6 +162,11 @@ void               camel_imapx_mailbox_handle_status_response
                                        (CamelIMAPXMailbox *mailbox,
                                         CamelIMAPXStatusResponse *response);
 
+void           camel_imapx_mailbox_lock_update
+                                       (CamelIMAPXMailbox *mailbox);
+void           camel_imapx_mailbox_unlock_update
+                                       (CamelIMAPXMailbox *mailbox);
+
 G_END_DECLS
 
 #endif /* CAMEL_IMAPX_MAILBOX_H */
diff --git a/camel/providers/imapx/camel-imapx-server.c b/camel/providers/imapx/camel-imapx-server.c
index 5b42485..1bdcc8d 100644
--- a/camel/providers/imapx/camel-imapx-server.c
+++ b/camel/providers/imapx/camel-imapx-server.c
@@ -8719,11 +8719,17 @@ camel_imapx_server_refresh_info (CamelIMAPXServer *is,
 
        QUEUE_UNLOCK (is);
 
+       if (registered)
+               camel_imapx_mailbox_lock_update (mailbox);
+
        if (registered && camel_imapx_job_run (job, is, error)) {
                changes = data->changes;
                data->changes = NULL;
        }
 
+       if (registered)
+               camel_imapx_mailbox_unlock_update (mailbox);
+
        camel_imapx_job_unref (job);
 
        return changes;
@@ -9051,8 +9057,14 @@ imapx_server_sync_changes (CamelIMAPXServer *is,
 
        QUEUE_UNLOCK (is);
 
+       if (job_type == IMAPX_JOB_SYNC_CHANGES && registered)
+               camel_imapx_mailbox_lock_update (mailbox);
+
        success = registered && camel_imapx_job_run (job, is, error);
 
+       if (job_type == IMAPX_JOB_SYNC_CHANGES && registered)
+               camel_imapx_mailbox_unlock_update (mailbox);
+
        camel_imapx_job_unref (job);
 
        g_object_unref (folder);


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