aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--camel/ChangeLog6
-rw-r--r--camel/providers/imap/camel-imap-private.h14
-rw-r--r--camel/providers/imap/camel-imap-wrapper.c26
-rw-r--r--camel/providers/imap/camel-imap-wrapper.h2
4 files changed, 46 insertions, 2 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index 82058c85bb..a9a0f69a14 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,3 +1,9 @@
+2001-01-23 Dan Winship <danw@ximian.com>
+
+ * providers/imap/camel-imap-wrapper.c: Add a lock around the
+ delayed loading, so two threads won't try to do it at the same
+ time.
+
2001-01-22 Dan Winship <danw@ximian.com>
* providers/vee/camel-vee-folder.c (camel_vee_folder_new): Set the
diff --git a/camel/providers/imap/camel-imap-private.h b/camel/providers/imap/camel-imap-private.h
index abcb3f8dd7..c7af3ee5e6 100644
--- a/camel/providers/imap/camel-imap-private.h
+++ b/camel/providers/imap/camel-imap-private.h
@@ -66,6 +66,20 @@ struct _CamelImapFolderPrivate {
#define CAMEL_IMAP_FOLDER_UNLOCK(f, l)
#endif
+struct _CamelImapWrapperPrivate {
+#ifdef ENABLE_THREADS
+ GMutex *lock;
+#endif
+};
+
+#ifdef ENABLE_THREADS
+#define CAMEL_IMAP_WRAPPER_LOCK(f, l) (g_mutex_lock(((CamelImapWrapper *)f)->priv->l))
+#define CAMEL_IMAP_WRAPPER_UNLOCK(f, l) (g_mutex_unlock(((CamelImapWrapper *)f)->priv->l))
+#else
+#define CAMEL_IMAP_WRAPPER_LOCK(f, l)
+#define CAMEL_IMAP_WRAPPER_UNLOCK(f, l)
+#endif
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
diff --git a/camel/providers/imap/camel-imap-wrapper.c b/camel/providers/imap/camel-imap-wrapper.c
index 2277b7747f..e4d06a009b 100644
--- a/camel/providers/imap/camel-imap-wrapper.c
+++ b/camel/providers/imap/camel-imap-wrapper.c
@@ -71,6 +71,22 @@ camel_imap_wrapper_finalize (CamelObject *object)
g_free (imap_wrapper->uid);
if (imap_wrapper->part)
g_free (imap_wrapper->part_spec);
+
+#ifdef ENABLE_THREADS
+ g_mutex_free (imap_wrapper->priv->lock);
+#endif
+ g_free (imap_wrapper->priv);
+}
+
+static void
+camel_imap_wrapper_init (gpointer object, gpointer klass)
+{
+ CamelImapWrapper *imap_wrapper = CAMEL_IMAP_WRAPPER (object);
+
+ imap_wrapper->priv = g_new0 (struct _CamelImapWrapperPrivate, 1);
+#ifdef ENABLE_THREADS
+ imap_wrapper->priv->lock = g_mutex_new ();
+#endif
}
CamelType
@@ -85,7 +101,7 @@ camel_imap_wrapper_get_type (void)
sizeof (CamelImapWrapperClass),
(CamelObjectClassInitFunc) camel_imap_wrapper_class_init,
NULL,
- NULL,
+ (CamelObjectInitFunc) camel_imap_wrapper_init,
(CamelObjectFinalizeFunc) camel_imap_wrapper_finalize);
}
@@ -106,8 +122,11 @@ write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
char *result, *p, *body;
int len;
- if (!data_wrapper->offline)
+ CAMEL_IMAP_WRAPPER_LOCK (imap_wrapper, lock);
+ if (!data_wrapper->offline) {
+ CAMEL_IMAP_WRAPPER_UNLOCK (imap_wrapper, lock);
return parent_class->write_to_stream (data_wrapper, stream);
+ }
store = CAMEL_IMAP_STORE (imap_wrapper->folder->parent_store);
CAMEL_IMAP_STORE_LOCK (store, command_lock);
@@ -180,9 +199,12 @@ write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
g_free (imap_wrapper->part_spec);
imap_wrapper->part = NULL;
+ CAMEL_IMAP_WRAPPER_UNLOCK (imap_wrapper, lock);
+
return parent_class->write_to_stream (data_wrapper, stream);
lose:
+ CAMEL_IMAP_WRAPPER_UNLOCK (imap_wrapper, lock);
errno = ENETUNREACH;
return -1;
}
diff --git a/camel/providers/imap/camel-imap-wrapper.h b/camel/providers/imap/camel-imap-wrapper.h
index 34b28424b7..8eb9d0969a 100644
--- a/camel/providers/imap/camel-imap-wrapper.h
+++ b/camel/providers/imap/camel-imap-wrapper.h
@@ -41,6 +41,8 @@ typedef struct
{
CamelDataWrapper parent_object;
+ struct _CamelImapWrapperPrivate *priv;
+
CamelFolder *folder;
char *uid, *part_spec;
CamelMimePart *part;