From a09f5534586962fe64f4d556839265f55ad5e8ec Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Sat, 24 Oct 2009 06:16:57 -0400 Subject: Prefer GLib mutexes over pthread mutexes. --- mail/em-subscribe-editor.c | 2 - mail/mail-folder-cache.c | 70 +++++++++--------- mail/mail-mt.c | 175 +++++++++++++++------------------------------ mail/mail-vfolder.c | 56 +++++++-------- 4 files changed, 118 insertions(+), 185 deletions(-) (limited to 'mail') diff --git a/mail/em-subscribe-editor.c b/mail/em-subscribe-editor.c index d572c89eaf..e9c933de50 100644 --- a/mail/em-subscribe-editor.c +++ b/mail/em-subscribe-editor.c @@ -26,8 +26,6 @@ #include -#include - #include "mail-tools.h" #include "mail-ops.h" #include "mail-mt.h" diff --git a/mail/mail-folder-cache.c b/mail/mail-folder-cache.c index 9bbb3737d2..e7144df0f9 100644 --- a/mail/mail-folder-cache.c +++ b/mail/mail-folder-cache.c @@ -30,7 +30,6 @@ #endif #define G_LOG_DOMAIN "folder tree" -#include #include #include @@ -75,10 +74,7 @@ /* note that many things are effectively serialised by having them run in the main loop thread which they need to do because of corba/gtk calls */ -#define LOCK(x) pthread_mutex_lock(&x) -#define UNLOCK(x) pthread_mutex_unlock(&x) - -static pthread_mutex_t info_lock = PTHREAD_MUTEX_INITIALIZER; +G_LOCK_DEFINE_STATIC (stores); struct _folder_info { struct _store_info *store_info; /* 'parent' link */ @@ -161,9 +157,9 @@ real_flush_updates (void) shell = e_shell_get_default (); default_model = em_folder_tree_model_get_default (); - LOCK(info_lock); + G_LOCK (stores); while ((up = (struct _folder_update *)e_dlist_remhead(&updates))) { - UNLOCK(info_lock); + G_UNLOCK (stores); if (up->remove) { if (up->delete) { @@ -230,10 +226,10 @@ real_flush_updates (void) free_update(up); - LOCK(info_lock); + G_LOCK (stores); } update_id = -1; - UNLOCK(info_lock); + G_UNLOCK (stores); } static void @@ -460,14 +456,14 @@ folder_changed (CamelObject *o, gpointer event_data, gpointer user_data) if (new > 0 || !last_newmail) time (&last_newmail); - LOCK(info_lock); + G_LOCK (stores); if (stores != NULL && (si = g_hash_table_lookup(stores, store)) != NULL && (mfi = g_hash_table_lookup(si->folders, folder->full_name)) != NULL && mfi->folder == folder) { update_1folder(mfi, new, NULL); } - UNLOCK(info_lock); + G_UNLOCK (stores); } static void @@ -479,14 +475,14 @@ folder_finalised(CamelObject *o, gpointer event_data, gpointer user_data) struct _folder_info *mfi; d(printf("Folder finalised '%s'!\n", ((CamelFolder *)o)->full_name)); - LOCK(info_lock); + G_LOCK (stores); if (stores != NULL && (si = g_hash_table_lookup(stores, store)) != NULL && (mfi = g_hash_table_lookup(si->folders, folder->full_name)) != NULL && mfi->folder == folder) { mfi->folder = NULL; } - UNLOCK(info_lock); + G_UNLOCK (stores); } static void @@ -510,18 +506,18 @@ void mail_note_folder(CamelFolder *folder) d(printf("noting folder '%s'\n", folder->full_name)); - LOCK(info_lock); + G_LOCK (stores); if (stores == NULL || (si = g_hash_table_lookup(stores, store)) == NULL || (mfi = g_hash_table_lookup(si->folders, folder->full_name)) == NULL) { w(g_warning("Noting folder before store initialised")); - UNLOCK(info_lock); + G_UNLOCK (stores); return; } /* dont do anything if we already have this */ if (mfi->folder == folder) { - UNLOCK(info_lock); + G_UNLOCK (stores); return; } @@ -529,7 +525,7 @@ void mail_note_folder(CamelFolder *folder) update_1folder(mfi, 0, NULL); - UNLOCK(info_lock); + G_UNLOCK (stores); camel_object_hook_event(folder, "folder_changed", folder_changed, NULL); camel_object_hook_event(folder, "renamed", folder_renamed, NULL); @@ -544,11 +540,11 @@ store_folder_subscribed(CamelObject *o, gpointer event_data, gpointer data) d(printf("Store folder subscribed '%s' store '%s' \n", fi->full_name, camel_url_to_string(((CamelService *)o)->url, 0))); - LOCK(info_lock); + G_LOCK (stores); si = g_hash_table_lookup(stores, o); if (si) setup_folder(fi, si); - UNLOCK(info_lock); + G_UNLOCK (stores); } static void @@ -577,7 +573,7 @@ store_folder_unsubscribed(CamelObject *o, gpointer event_data, gpointer data) d(printf("Store Folder deleted: %s\n", fi->full_name)); - LOCK(info_lock); + G_LOCK (stores); si = g_hash_table_lookup(stores, store); if (si) { mfi = g_hash_table_lookup(si->folders, fi->full_name); @@ -588,7 +584,7 @@ store_folder_unsubscribed(CamelObject *o, gpointer event_data, gpointer data) free_folder_info(mfi); } } - UNLOCK(info_lock); + G_UNLOCK (stores); } static void @@ -735,7 +731,7 @@ store_folder_renamed(CamelObject *o, gpointer event_data, gpointer data) d(printf("Folder renamed: oldbase = '%s' new->full = '%s'\n", info->old_base, info->new->full_name)); - LOCK(info_lock); + G_LOCK (stores); si = g_hash_table_lookup(stores, store); if (si) { GPtrArray *folders = g_ptr_array_new(); @@ -755,7 +751,7 @@ store_folder_renamed(CamelObject *o, gpointer event_data, gpointer data) g_ptr_array_free(folders, TRUE); } - UNLOCK(info_lock); + G_UNLOCK (stores); } struct _update_data { @@ -793,7 +789,7 @@ mail_note_store_remove(CamelStore *store) return; d(printf("store removed!!\n")); - LOCK(info_lock); + G_LOCK (stores); si = g_hash_table_lookup(stores, store); if (si) { g_hash_table_remove(stores, store); @@ -821,7 +817,7 @@ mail_note_store_remove(CamelStore *store) g_free(si); } - UNLOCK(info_lock); + G_UNLOCK (stores); } static gboolean @@ -833,7 +829,7 @@ update_folders(CamelStore *store, CamelFolderInfo *fi, gpointer data) d(printf("Got folderinfo for store %s\n", store->parent_object.provider->protocol)); - LOCK(info_lock); + G_LOCK (stores); si = g_hash_table_lookup(stores, store); if (si && !ud->cancel) { /* the 'si' is still there, so we can remove ourselves from its list */ @@ -843,7 +839,7 @@ update_folders(CamelStore *store, CamelFolderInfo *fi, gpointer data) if (fi) create_folders(fi, si); } - UNLOCK(info_lock); + G_UNLOCK (stores); if (ud->done) res = ud->done (store, fi, ud->data); @@ -920,11 +916,11 @@ ping_store (gpointer key, gpointer val, gpointer user_data) static gboolean ping_cb (gpointer user_data) { - LOCK (info_lock); + G_LOCK (stores); g_hash_table_foreach (stores, ping_store, NULL); - UNLOCK (info_lock); + G_UNLOCK (stores); return TRUE; } @@ -934,7 +930,7 @@ store_online_cb (CamelStore *store, gpointer data) { struct _update_data *ud = data; - LOCK(info_lock); + G_LOCK (stores); if (g_hash_table_lookup(stores, store) != NULL && !ud->cancel) { /* re-use the cancel id. we're already in the store update list too */ @@ -945,7 +941,7 @@ store_online_cb (CamelStore *store, gpointer data) g_free(ud); } - UNLOCK(info_lock); + G_UNLOCK (stores); } void @@ -961,7 +957,7 @@ mail_note_store(CamelStore *store, CamelOperation *op, g_return_if_fail (CAMEL_IS_STORE(store)); g_return_if_fail (mail_in_main_thread()); - LOCK(info_lock); + G_LOCK (stores); if (stores == NULL) { stores = g_hash_table_new(NULL, NULL); @@ -1016,7 +1012,7 @@ mail_note_store(CamelStore *store, CamelOperation *op, e_dlist_addtail (&si->folderinfo_updates, (EDListNode *) ud); - UNLOCK(info_lock); + G_UNLOCK (stores); /* there is potential for race here, but it is safe as we check for the store anyway */ if (hook) { @@ -1060,7 +1056,7 @@ gint mail_note_get_folder_from_uri(const gchar *uri, CamelFolder **folderp) fi.url = camel_url_new(uri, NULL); - LOCK(info_lock); + G_LOCK (stores); g_hash_table_foreach(stores, (GHFunc)storeinfo_find_folder_info, &fi); if (folderp) { if (fi.fi && fi.fi->folder) { @@ -1070,7 +1066,7 @@ gint mail_note_get_folder_from_uri(const gchar *uri, CamelFolder **folderp) *folderp = NULL; } } - UNLOCK(info_lock); + G_UNLOCK (stores); camel_url_free(fi.url); @@ -1088,14 +1084,14 @@ mail_folder_cache_get_folder_info_flags (CamelFolder *folder, gint *flags) fi.url = camel_url_new (uri, NULL); - LOCK(info_lock); + G_LOCK (stores); g_hash_table_foreach(stores, (GHFunc)storeinfo_find_folder_info, &fi); if (flags) { if (fi.fi) { *flags = fi.fi->flags; } } - UNLOCK(info_lock); + G_UNLOCK (stores); camel_url_free(fi.url); g_free (uri); diff --git a/mail/mail-mt.c b/mail/mail-mt.c index f87a8f2e91..aa7f5727e5 100644 --- a/mail/mail-mt.c +++ b/mail/mail-mt.c @@ -20,7 +20,6 @@ #include #include #include -#include #include #include @@ -45,21 +44,11 @@ #include "mail-mt.h" /*#define MALLOC_CHECK*/ -#define LOG_OPS -#define LOG_LOCKS #define d(x) static void set_stop(gint sensitive); static void mail_operation_status(CamelOperation *op, const gchar *what, gint pc, gpointer data); -#ifdef LOG_LOCKS -#define MAIL_MT_LOCK(x) (log_locks?fprintf(log, "%" G_GINT64_MODIFIER "x: lock " # x "\n", e_util_pthread_id(pthread_self())):0, pthread_mutex_lock(&x)) -#define MAIL_MT_UNLOCK(x) (log_locks?fprintf(log, "%" G_GINT64_MODIFIER "x: unlock " # x "\n", e_util_pthread_id(pthread_self())): 0, pthread_mutex_unlock(&x)) -#else -#define MAIL_MT_LOCK(x) pthread_mutex_lock(&x) -#define MAIL_MT_UNLOCK(x) pthread_mutex_unlock(&x) -#endif - /* background operation status stuff */ struct _MailMsgPrivate { gint activity_state; /* sigh sigh sigh, we need to keep track of the state external to the @@ -69,16 +58,10 @@ struct _MailMsgPrivate { gboolean cancelable; }; -/* mail_msg stuff */ -#ifdef LOG_OPS -static FILE *log; -static gint log_ops, log_locks, log_init; -#endif - static guint mail_msg_seq; /* sequence number of each message */ static GHashTable *mail_msg_active_table; /* table of active messages, must hold mail_msg_lock to access */ -static pthread_mutex_t mail_msg_lock = PTHREAD_MUTEX_INITIALIZER; -static pthread_cond_t mail_msg_cond = PTHREAD_COND_INITIALIZER; +static GMutex *mail_msg_lock; +static GCond *mail_msg_cond; MailAsyncEvent *mail_async_event; @@ -87,35 +70,8 @@ mail_msg_new (MailMsgInfo *info) { MailMsg *msg; - MAIL_MT_LOCK(mail_msg_lock); - -#if defined(LOG_OPS) || defined(LOG_LOCKS) - if (!log_init) { - time_t now = time(NULL); - - log_init = TRUE; - log_ops = getenv("EVOLUTION_MAIL_LOG_OPS") != NULL; - log_locks = getenv("EVOLUTION_MAIL_LOG_LOCKS") != NULL; - if (log_ops || log_locks) { - log = fopen("evolution-mail-ops.log", "w+"); - if (log) { - setvbuf(log, NULL, _IOLBF, 0); - fprintf(log, "Started evolution-mail: %s\n", ctime(&now)); - g_warning("Logging mail operations to evolution-mail-ops.log"); - - if (log_ops) - fprintf(log, "Logging async operations\n"); + g_mutex_lock (mail_msg_lock); - if (log_locks) { - fprintf(log, "%" G_GINT64_MODIFIER "x: lock mail_msg_lock\n", e_util_pthread_id(pthread_self())); - } - } else { - g_warning ("Could not open log file: %s", g_strerror(errno)); - log_ops = log_locks = FALSE; - } - } - } -#endif msg = g_slice_alloc0 (info->size); msg->info = info; msg->ref_count = 1; @@ -129,11 +85,7 @@ mail_msg_new (MailMsgInfo *info) d(printf("New message %p\n", msg)); -#ifdef LOG_OPS - if (log_ops) - fprintf(log, "%p: New\n", (gpointer) msg); -#endif - MAIL_MT_UNLOCK(mail_msg_lock); + g_mutex_unlock (mail_msg_lock); return msg; } @@ -234,21 +186,11 @@ mail_msg_unref (gpointer msg) if (mail_msg->info->free) mail_msg->info->free(mail_msg); - MAIL_MT_LOCK(mail_msg_lock); + g_mutex_lock (mail_msg_lock); -#ifdef LOG_OPS - if (log_ops) { - const gchar *description; - - description = camel_exception_get_description (&mail_msg->ex); - if (description == NULL) - description = "None"; - fprintf(log, "%p: Free (exception `%s')\n", msg, description); - } -#endif g_hash_table_remove ( mail_msg_active_table, GINT_TO_POINTER (mail_msg->seq)); - pthread_cond_broadcast (&mail_msg_cond); + g_cond_broadcast (mail_msg_cond); /* We need to make sure we dont lose a reference here YUCK YUCK */ /* This is tightly integrated with the code in do_op_status, @@ -256,7 +198,7 @@ mail_msg_unref (gpointer msg) if (mail_msg->priv->activity_state == 1) { /* tell the other to free it itself */ mail_msg->priv->activity_state = 3; - MAIL_MT_UNLOCK(mail_msg_lock); + g_mutex_unlock (mail_msg_lock); return; } else { activity = mail_msg->priv->activity; @@ -265,7 +207,7 @@ mail_msg_unref (gpointer msg) error = mail_msg->priv->error; } - MAIL_MT_UNLOCK(mail_msg_lock); + g_mutex_unlock (mail_msg_lock); mail_msg_free (mail_msg); @@ -347,13 +289,14 @@ void mail_msg_cancel(guint msgid) { MailMsg *m; - MAIL_MT_LOCK(mail_msg_lock); + g_mutex_lock (mail_msg_lock); + m = g_hash_table_lookup(mail_msg_active_table, GINT_TO_POINTER(msgid)); if (m && m->cancel) camel_operation_cancel(m->cancel); - MAIL_MT_UNLOCK(mail_msg_lock); + g_mutex_unlock (mail_msg_lock); } /* waits for a message to be finished processing (freed) @@ -363,23 +306,23 @@ void mail_msg_wait(guint msgid) MailMsg *m; if (mail_in_main_thread ()) { - MAIL_MT_LOCK(mail_msg_lock); + g_mutex_lock (mail_msg_lock); m = g_hash_table_lookup(mail_msg_active_table, GINT_TO_POINTER(msgid)); while (m) { - MAIL_MT_UNLOCK(mail_msg_lock); + g_mutex_unlock (mail_msg_lock); gtk_main_iteration(); - MAIL_MT_LOCK(mail_msg_lock); + g_mutex_lock (mail_msg_lock); m = g_hash_table_lookup(mail_msg_active_table, GINT_TO_POINTER(msgid)); } - MAIL_MT_UNLOCK(mail_msg_lock); + g_mutex_unlock (mail_msg_lock); } else { - MAIL_MT_LOCK(mail_msg_lock); + g_mutex_lock (mail_msg_lock); m = g_hash_table_lookup(mail_msg_active_table, GINT_TO_POINTER(msgid)); while (m) { - pthread_cond_wait(&mail_msg_cond, &mail_msg_lock); + g_cond_wait (mail_msg_cond, mail_msg_lock); m = g_hash_table_lookup(mail_msg_active_table, GINT_TO_POINTER(msgid)); } - MAIL_MT_UNLOCK(mail_msg_lock); + g_mutex_unlock (mail_msg_lock); } } @@ -387,12 +330,12 @@ gint mail_msg_active(guint msgid) { gint active; - MAIL_MT_LOCK(mail_msg_lock); + g_mutex_lock (mail_msg_lock); if (msgid == (guint)-1) active = g_hash_table_size(mail_msg_active_table) > 0; else active = g_hash_table_lookup(mail_msg_active_table, GINT_TO_POINTER(msgid)) != NULL; - MAIL_MT_UNLOCK(mail_msg_lock); + g_mutex_unlock (mail_msg_lock); return active; } @@ -400,19 +343,19 @@ gint mail_msg_active(guint msgid) void mail_msg_wait_all(void) { if (mail_in_main_thread ()) { - MAIL_MT_LOCK(mail_msg_lock); + g_mutex_lock (mail_msg_lock); while (g_hash_table_size(mail_msg_active_table) > 0) { - MAIL_MT_UNLOCK(mail_msg_lock); + g_mutex_unlock (mail_msg_lock); gtk_main_iteration(); - MAIL_MT_LOCK(mail_msg_lock); + g_mutex_lock (mail_msg_lock); } - MAIL_MT_UNLOCK(mail_msg_lock); + g_mutex_unlock (mail_msg_lock); } else { - MAIL_MT_LOCK(mail_msg_lock); + g_mutex_lock (mail_msg_lock); while (g_hash_table_size(mail_msg_active_table) > 0) { - pthread_cond_wait(&mail_msg_cond, &mail_msg_lock); + g_cond_wait (mail_msg_cond, mail_msg_lock); } - MAIL_MT_UNLOCK(mail_msg_lock); + g_mutex_unlock (mail_msg_lock); } } @@ -425,7 +368,7 @@ mail_cancel_hook_add (GHookFunc func, gpointer data) { GHook *hook; - MAIL_MT_LOCK (mail_msg_lock); + g_mutex_lock (mail_msg_lock); if (!cancel_hook_list.is_setup) g_hook_list_init (&cancel_hook_list, sizeof (GHook)); @@ -436,7 +379,7 @@ mail_cancel_hook_add (GHookFunc func, gpointer data) g_hook_append (&cancel_hook_list, hook); - MAIL_MT_UNLOCK (mail_msg_lock); + g_mutex_unlock (mail_msg_lock); return hook; } @@ -444,12 +387,12 @@ mail_cancel_hook_add (GHookFunc func, gpointer data) void mail_cancel_hook_remove (GHook *hook) { - MAIL_MT_LOCK (mail_msg_lock); + g_mutex_lock (mail_msg_lock); g_return_if_fail (cancel_hook_list.is_setup); g_hook_destroy_link (&cancel_hook_list, hook); - MAIL_MT_UNLOCK (mail_msg_lock); + g_mutex_unlock (mail_msg_lock); } void @@ -457,12 +400,12 @@ mail_cancel_all (void) { camel_operation_cancel (NULL); - MAIL_MT_LOCK (mail_msg_lock); + g_mutex_lock (mail_msg_lock); if (cancel_hook_list.is_setup) g_hook_list_invoke (&cancel_hook_list, FALSE); - MAIL_MT_UNLOCK (mail_msg_lock); + g_mutex_unlock (mail_msg_lock); } void @@ -566,6 +509,9 @@ mail_msg_cleanup (void) void mail_msg_init (void) { + mail_msg_lock = g_mutex_new (); + mail_msg_cond = g_cond_new (); + main_loop_queue = g_async_queue_new (); msg_reply_queue = g_async_queue_new (); @@ -653,19 +599,13 @@ mail_in_main_thread (void) /* ********************************************************************** */ -/* locks */ -static pthread_mutex_t status_lock = PTHREAD_MUTEX_INITIALIZER; - -/* ********************************************************************** */ - struct _proxy_msg { MailMsg base; MailAsyncEvent *ea; mail_async_event_t type; - pthread_t thread; - gint have_thread; + GThread *thread; MailAsyncFunc func; gpointer o; @@ -676,10 +616,9 @@ struct _proxy_msg { static void do_async_event(struct _proxy_msg *m) { - m->thread = pthread_self(); - m->have_thread = TRUE; + m->thread = g_thread_self (); m->func(m->o, m->event_data, m->data); - m->have_thread = FALSE; + m->thread = NULL; g_mutex_lock(m->ea->lock); m->ea->tasks = g_slist_remove(m->ea->tasks, m); @@ -726,7 +665,7 @@ gint mail_async_event_emit(MailAsyncEvent *ea, mail_async_event_t type, MailAsyn m->data = data; m->ea = ea; m->type = type; - m->have_thread = FALSE; + m->thread = NULL; id = m->base.seq; g_mutex_lock(ea->lock); @@ -749,14 +688,13 @@ gint mail_async_event_emit(MailAsyncEvent *ea, mail_async_event_t type, MailAsyn gint mail_async_event_destroy(MailAsyncEvent *ea) { gint id; - pthread_t thread = pthread_self(); struct _proxy_msg *m; g_mutex_lock(ea->lock); while (ea->tasks) { m = ea->tasks->data; id = m->base.seq; - if (m->have_thread && pthread_equal(m->thread, thread)) { + if (m->thread == g_thread_self ()) { g_warning("Destroying async event from inside an event, returning EDEADLK"); g_mutex_unlock(ea->lock); errno = EDEADLK; @@ -884,6 +822,7 @@ mail_call_main (mail_call_t type, MailMainFunc func, ...) /* ********************************************************************** */ /* locked via status_lock */ static gint busy_state; +G_LOCK_DEFINE_STATIC (busy_state); static void do_set_busy(MailMsg *mm) @@ -903,26 +842,30 @@ void mail_enable_stop(void) { MailMsg *m; - MAIL_MT_LOCK(status_lock); + G_LOCK (busy_state); + busy_state++; if (busy_state == 1) { m = mail_msg_new(&set_busy_info); mail_msg_main_loop_push(m); } - MAIL_MT_UNLOCK(status_lock); + + G_UNLOCK (busy_state); } void mail_disable_stop(void) { MailMsg *m; - MAIL_MT_LOCK(status_lock); + G_LOCK (busy_state); + busy_state--; if (busy_state == 0) { m = mail_msg_new(&set_busy_info); mail_msg_main_loop_push(m); } - MAIL_MT_UNLOCK(status_lock); + + G_UNLOCK (busy_state); } /* ******************************************************************************** */ @@ -958,12 +901,12 @@ op_status_exec (struct _op_status_msg *m) shell = e_shell_get_default (); shell_backend = e_shell_get_backend_by_name (shell, "mail"); - MAIL_MT_LOCK (mail_msg_lock); + g_mutex_lock (mail_msg_lock); msg = g_hash_table_lookup (mail_msg_active_table, m->data); if (msg == NULL) { - MAIL_MT_UNLOCK (mail_msg_lock); + g_mutex_unlock (mail_msg_lock); return; } @@ -986,12 +929,12 @@ op_status_exec (struct _op_status_msg *m) /* its being created/removed? well leave it be */ if (data->activity_state == 1 || data->activity_state == 3) { - MAIL_MT_UNLOCK (mail_msg_lock); + g_mutex_unlock (mail_msg_lock); return; } else { data->activity_state = 1; - MAIL_MT_UNLOCK (mail_msg_lock); + g_mutex_unlock (mail_msg_lock); if (msg->info->desc) what = msg->info->desc (msg); else if (m->what) @@ -1012,13 +955,13 @@ op_status_exec (struct _op_status_msg *m) GUINT_TO_POINTER (msg->seq)); g_free (what); - MAIL_MT_LOCK (mail_msg_lock); + g_mutex_lock (mail_msg_lock); if (data->activity_state == 3) { EActivity *activity; activity = g_object_ref (data->activity); - MAIL_MT_UNLOCK (mail_msg_lock); + g_mutex_unlock (mail_msg_lock); mail_msg_free (msg); if (activity != 0) @@ -1027,16 +970,16 @@ op_status_exec (struct _op_status_msg *m) NULL, activity, NULL); } else { data->activity_state = 2; - MAIL_MT_UNLOCK (mail_msg_lock); + g_mutex_unlock (mail_msg_lock); } return; } } else if (data->activity != NULL) { - MAIL_MT_UNLOCK (mail_msg_lock); + g_mutex_unlock (mail_msg_lock); e_activity_set_primary_text (data->activity, out); e_activity_set_percent (data->activity, pc / 100.0); } else { - MAIL_MT_UNLOCK (mail_msg_lock); + g_mutex_unlock (mail_msg_lock); } } diff --git a/mail/mail-vfolder.c b/mail/mail-vfolder.c index b20cc266f2..1612b283c2 100644 --- a/mail/mail-vfolder.c +++ b/mail/mail-vfolder.c @@ -21,7 +21,6 @@ */ #include -#include #include #include @@ -59,7 +58,7 @@ static EMVFolderContext *context; /* context remains open all time */ CamelStore *vfolder_store; /* the 1 static vfolder store */ /* lock for accessing shared resources (below) */ -static pthread_mutex_t vfolder_lock = PTHREAD_MUTEX_INITIALIZER; +G_LOCK_DEFINE_STATIC (vfolder); static GList *source_folders_remote; /* list of source folder uri's - remote ones */ static GList *source_folders_local; /* list of source folder uri's - local ones */ @@ -72,9 +71,6 @@ extern CamelSession *session; static void rule_changed(FilterRule *rule, CamelFolder *folder); -#define LOCK() pthread_mutex_lock(&vfolder_lock); -#define UNLOCK() pthread_mutex_unlock(&vfolder_lock); - /* ********************************************************************** */ struct _setup_msg { @@ -449,7 +445,7 @@ mail_vfolder_add_uri(CamelStore *store, const gchar *curi, gint remove) is_ignore = uri_is_ignore(store, curi); - LOCK(); + G_LOCK (vfolder); /* d(printf("%s uri to check: %s\n", remove?"Removing":"Adding", uri)); */ @@ -519,7 +515,7 @@ mail_vfolder_add_uri(CamelStore *store, const gchar *curi, gint remove) } done: - UNLOCK(); + G_UNLOCK (vfolder); if (folders != NULL) vfolder_adduri(curi, folders, remove); @@ -549,7 +545,7 @@ mail_vfolder_delete_uri(CamelStore *store, const gchar *curi) changed = g_string_new (""); - LOCK(); + G_LOCK (vfolder); if (context == NULL) goto done; @@ -597,7 +593,7 @@ done: source_folders_local = g_list_remove_link(source_folders_local, link); } - UNLOCK(); + G_UNLOCK (vfolder); if (changed->str[0]) { GtkWidget *dialog; @@ -638,7 +634,7 @@ mail_vfolder_rename_uri(CamelStore *store, const gchar *cfrom, const gchar *cto) from = em_uri_from_camel(cfrom); to = em_uri_from_camel(cto); - LOCK(); + G_LOCK (vfolder); /* see if any rules directly reference this removed uri */ rule = NULL; @@ -668,7 +664,7 @@ mail_vfolder_rename_uri(CamelStore *store, const gchar *cfrom, const gchar *cto) } } - UNLOCK(); + G_UNLOCK (vfolder); if (changed) { const gchar *data_dir; @@ -738,15 +734,15 @@ rule_changed(FilterRule *rule, CamelFolder *folder) gpointer key; gpointer oldfolder; - LOCK(); + G_LOCK (vfolder); d(printf("Changing folder name in hash table to '%s'\n", rule->name)); if (g_hash_table_lookup_extended (vfolder_hash, folder->full_name, &key, &oldfolder)) { g_hash_table_remove (vfolder_hash, key); g_free (key); g_hash_table_insert (vfolder_hash, g_strdup(rule->name), folder); - UNLOCK(); + G_UNLOCK (vfolder); } else { - UNLOCK(); + G_UNLOCK (vfolder); g_warning("couldn't find a vfolder rule in our table? %s", folder->full_name); } @@ -761,12 +757,12 @@ rule_changed(FilterRule *rule, CamelFolder *folder) /* find any (currently available) folders, and add them to the ones to open */ rule_add_sources(((EMVFolderRule *)rule)->sources, &sources_folder, &sources_uri); - LOCK(); + G_LOCK (vfolder); if (((EMVFolderRule *)rule)->with == EM_VFOLDER_RULE_WITH_LOCAL || ((EMVFolderRule *)rule)->with == EM_VFOLDER_RULE_WITH_LOCAL_REMOTE_ACTIVE) rule_add_sources(source_folders_local, &sources_folder, &sources_uri); if (((EMVFolderRule *)rule)->with == EM_VFOLDER_RULE_WITH_REMOTE_ACTIVE || ((EMVFolderRule *)rule)->with == EM_VFOLDER_RULE_WITH_LOCAL_REMOTE_ACTIVE) rule_add_sources(source_folders_remote, &sources_folder, &sources_uri); - UNLOCK(); + G_UNLOCK (vfolder); query = g_string_new(""); filter_rule_build_code(rule, query); @@ -787,9 +783,9 @@ static void context_rule_added(RuleContext *ctx, FilterRule *rule) if (folder) { g_signal_connect(rule, "changed", G_CALLBACK(rule_changed), folder); - LOCK(); + G_LOCK (vfolder); g_hash_table_insert(vfolder_hash, g_strdup(rule->name), folder); - UNLOCK(); + G_UNLOCK (vfolder); rule_changed(rule, folder); } @@ -803,12 +799,12 @@ static void context_rule_removed(RuleContext *ctx, FilterRule *rule) /* TODO: remove from folder info cache? */ - LOCK(); + G_LOCK (vfolder); if (g_hash_table_lookup_extended (vfolder_hash, rule->name, &key, &folder)) { g_hash_table_remove (vfolder_hash, key); g_free (key); } - UNLOCK(); + G_UNLOCK (vfolder); camel_store_delete_folder(vfolder_store, rule->name, NULL); /* this must be unref'd after its deleted */ @@ -839,7 +835,7 @@ store_folder_deleted(CamelObject *o, gpointer event_data, gpointer data) /* Warning not thread safe, but might be enough */ - LOCK(); + G_LOCK (vfolder); /* delete it from our list */ rule = rule_context_find_rule((RuleContext *)context, info->full_name, NULL); @@ -861,7 +857,7 @@ store_folder_deleted(CamelObject *o, gpointer event_data, gpointer data) g_warning("Cannot find rule for deleted vfolder '%s'", info->name); } - UNLOCK(); + G_UNLOCK (vfolder); } static void @@ -878,7 +874,7 @@ store_folder_renamed(CamelObject *o, gpointer event_data, gpointer data) d(printf("Folder renamed to '%s' from '%s'\n", info->new->full_name, info->old_base)); /* Folder is already renamed? */ - LOCK(); + G_LOCK (vfolder); d(printf("Changing folder name in hash table to '%s'\n", info->new->full_name)); if (g_hash_table_lookup_extended (vfolder_hash, info->old_base, &key, &folder)) { const gchar *data_dir; @@ -889,7 +885,7 @@ store_folder_renamed(CamelObject *o, gpointer event_data, gpointer data) rule = rule_context_find_rule((RuleContext *)context, info->old_base, NULL); if (!rule) { - UNLOCK (); + G_UNLOCK (vfolder); g_warning ("Rule shouldn't be NULL\n"); return; } @@ -904,9 +900,9 @@ store_folder_renamed(CamelObject *o, gpointer event_data, gpointer data) rule_context_save((RuleContext *)context, user); g_free(user); - UNLOCK(); + G_UNLOCK (vfolder); } else { - UNLOCK(); + G_UNLOCK (vfolder); g_warning("couldn't find a vfolder rule in our table? %s", info->new->full_name); } } @@ -915,7 +911,7 @@ void vfolder_load_storage(void) { /* lock for loading storage, it is safe to call it more than once */ - static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; + G_LOCK_DEFINE_STATIC (vfolder_hash); const gchar *data_dir; gchar *user, *storeuri; @@ -923,17 +919,17 @@ vfolder_load_storage(void) gchar *xmlfile; GConfClient *gconf; - pthread_mutex_lock (&lock); + G_LOCK (vfolder_hash); if (vfolder_hash) { /* we have already initialized */ - pthread_mutex_unlock (&lock); + G_UNLOCK (vfolder_hash); return; } vfolder_hash = g_hash_table_new(g_str_hash, g_str_equal); - pthread_mutex_unlock (&lock); + G_UNLOCK (vfolder_hash); /* first, create the vfolder store, and set it up */ data_dir = em_utils_get_data_dir (); -- cgit v1.2.3