From 6de256c2a2b23f30d35e4a2213ad5839bf141d06 Mon Sep 17 00:00:00 2001 From: Not Zed Date: Sun, 24 Dec 2000 00:46:20 +0000 Subject: Lock the command channel while searching. (imap_body_contains): If 2000-12-24 Not Zed * providers/imap/camel-imap-search.c (imap_body_contains): Lock the command channel while searching. (imap_body_contains): If performing a whole uid search, then add references to our own summary items, dont look it up in the folder. This way they can't vanish unexpectedly. * providers/imap/camel-imap-folder.h (CamelImapFolder): Added a private field. * providers/imap/camel-imap-private.h: Added lock for imap searches. * Merge from camel-mt-branch. * providers/imap/camel-imap-folder.c (imap_update_summary): Merge fix, use the folder->summary. (imap_get_message_flags, imap_set_message_flags, imap_get_message_user_flag, imap_set_message_user_flag): Removed again. (camel_imap_folder_init): Setup private data/lock. (imap_finalize): Free private data/search lock. (imap_search_free): Lock the search_lock. (imap_search_by_expression): Lock the search lock when using the search object. Also copy/ref hte summary, rather than getting it directly. (imap_refresh_info): Free any info lookups. Use folder->summary not imap_folder->summary. And lock around commands. svn path=/trunk/; revision=7150 --- camel/camel-exception.c | 84 +++++++++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 38 deletions(-) (limited to 'camel/camel-exception.c') diff --git a/camel/camel-exception.c b/camel/camel-exception.c index ef90136859..6f07183f2b 100644 --- a/camel/camel-exception.c +++ b/camel/camel-exception.c @@ -27,7 +27,21 @@ #include #include "camel-exception.h" +/* i dont know why gthread_mutex stuff even exists, this is easier */ +/* also, i'm not convinced mutexes are needed here. But it + doesn't really hurt either */ +#ifdef ENABLE_THREADS +#include + +static pthread_mutex_t exception_mutex = PTHREAD_MUTEX_INITIALIZER; + +#define CAMEL_EXCEPTION_LOCK(e) (pthread_mutex_lock(&exception_mutex)) +#define CAMEL_EXCEPTION_UNLOCK(e) (pthread_mutex_unlock(&exception_mutex)) +#else +#define CAMEL_EXCEPTION_LOCK(e) +#define CAMEL_EXCEPTION_UNLOCK(e) +#endif /** * camel_exception_new: allocate a new exception object. @@ -83,19 +97,18 @@ camel_exception_init (CamelException *ex) void camel_exception_clear (CamelException *exception) { - if (!exception) return; - - /* free the description text */ + if (!exception) + return; + + CAMEL_EXCEPTION_LOCK(exception); + if (exception->desc) g_free (exception->desc); exception->desc = NULL; - - /* set the Exception Id to NULL */ exception->id = CAMEL_EXCEPTION_NONE; -} - - + CAMEL_EXCEPTION_UNLOCK(exception); +} /** * camel_exception_free: Free an exception @@ -108,12 +121,11 @@ camel_exception_clear (CamelException *exception) void camel_exception_free (CamelException *exception) { - if (!exception) return; + if (!exception) + return; - /* free the description text */ if (exception->desc) g_free (exception->desc); - /* free the exeption itself */ g_free (exception); } @@ -137,17 +149,19 @@ camel_exception_set (CamelException *ex, ExceptionId id, const char *desc) { - /* if no exception is given, do nothing */ - if (!ex) return; + if (!ex) + return; + + CAMEL_EXCEPTION_LOCK(exception); ex->id = id; - /* remove the previous exception description */ if (ex->desc) - g_free (ex->desc); - ex->desc = g_strdup (desc); -} + g_free(ex->desc); + ex->desc = g_strdup(desc); + CAMEL_EXCEPTION_UNLOCK(exception); +} /** * camel_exception_setv: set an exception @@ -178,25 +192,22 @@ camel_exception_setv (CamelException *ex, { va_list args; - /* if no exception is given, do nothing */ - if (!ex) return; + if (!ex) + return; + + CAMEL_EXCEPTION_LOCK(exception); if (ex->desc) g_free (ex->desc); - /* create the temporary exception string */ va_start(args, format); ex->desc = g_strdup_vprintf (format, args); va_end (args); ex->id = id; -} - - - - - + CAMEL_EXCEPTION_UNLOCK(exception); +} /** * camel_exception_xfer: transfer an exception @@ -212,6 +223,8 @@ void camel_exception_xfer (CamelException *ex_dst, CamelException *ex_src) { + CAMEL_EXCEPTION_LOCK(exception); + if (ex_dst->desc) g_free (ex_dst->desc); @@ -220,13 +233,9 @@ camel_exception_xfer (CamelException *ex_dst, ex_src->desc = NULL; ex_src->id = CAMEL_EXCEPTION_NONE; -} - - - - - + CAMEL_EXCEPTION_UNLOCK(exception); +} /** * camel_exception_get_id: get the exception id @@ -246,9 +255,6 @@ camel_exception_get_id (CamelException *ex) return CAMEL_EXCEPTION_NONE; } - - - /** * camel_exception_get_description: get the description of an exception. * @ex: The exception object @@ -262,8 +268,10 @@ camel_exception_get_id (CamelException *ex) const gchar * camel_exception_get_description (CamelException *ex) { + char *ret = NULL; + if (ex) - return ex->desc; - else - return NULL; + ret = ex->desc; + + return ret; } -- cgit v1.2.3