diff options
author | Dan Winship <danw@src.gnome.org> | 2001-01-24 04:34:50 +0800 |
---|---|---|
committer | Dan Winship <danw@src.gnome.org> | 2001-01-24 04:34:50 +0800 |
commit | 5d7f815b3eede63ce843c7de7a3d2302c6b93586 (patch) | |
tree | 2ff2b1789ad7455a4aaf14304323efd8194ca387 /camel/providers | |
parent | 4028f454b6c274fa093056180af8d11e5c7bfd1e (diff) | |
download | gsoc2013-evolution-5d7f815b3eede63ce843c7de7a3d2302c6b93586.tar.gz gsoc2013-evolution-5d7f815b3eede63ce843c7de7a3d2302c6b93586.tar.zst gsoc2013-evolution-5d7f815b3eede63ce843c7de7a3d2302c6b93586.zip |
Add a lock around the delayed loading, so two threads won't try to do it
* 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.
svn path=/trunk/; revision=7752
Diffstat (limited to 'camel/providers')
-rw-r--r-- | camel/providers/imap/camel-imap-private.h | 14 | ||||
-rw-r--r-- | camel/providers/imap/camel-imap-wrapper.c | 26 | ||||
-rw-r--r-- | camel/providers/imap/camel-imap-wrapper.h | 2 |
3 files changed, 40 insertions, 2 deletions
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; |