aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2009-10-24 18:16:57 +0800
committerMatthew Barnes <mbarnes@redhat.com>2009-10-27 21:25:00 +0800
commita09f5534586962fe64f4d556839265f55ad5e8ec (patch)
tree9e8e68e0c9726f5da2672f194da2677e265e36be
parent555c178a7d52ae4aa5a52fa78bbbc0f70f4cc576 (diff)
downloadgsoc2013-evolution-a09f5534586962fe64f4d556839265f55ad5e8ec.tar.gz
gsoc2013-evolution-a09f5534586962fe64f4d556839265f55ad5e8ec.tar.zst
gsoc2013-evolution-a09f5534586962fe64f4d556839265f55ad5e8ec.zip
Prefer GLib mutexes over pthread mutexes.
-rw-r--r--e-util/e-icon-factory.c2
-rw-r--r--mail/em-subscribe-editor.c2
-rw-r--r--mail/mail-folder-cache.c70
-rw-r--r--mail/mail-mt.c175
-rw-r--r--mail/mail-vfolder.c56
-rw-r--r--plugins/sa-junk-plugin/em-junk-filter.c61
6 files changed, 148 insertions, 218 deletions
diff --git a/e-util/e-icon-factory.c b/e-util/e-icon-factory.c
index 496a96a7e4..cdbf39c788 100644
--- a/e-util/e-icon-factory.c
+++ b/e-util/e-icon-factory.c
@@ -28,8 +28,6 @@
#include <sys/types.h>
#include <sys/stat.h>
-#include <pthread.h>
-
#define GNOME_DESKTOP_USE_UNSTABLE_API
#include <libgnomeui/gnome-desktop-thumbnail.h>
#undef GNOME_DESKTOP_USE_UNSTABLE_API
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 <string.h>
-#include <pthread.h>
-
#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 <pthread.h>
#include <string.h>
#include <time.h>
@@ -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 <stdio.h>
#include <string.h>
#include <unistd.h>
-#include <pthread.h>
#include <errno.h>
#include <glib.h>
@@ -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 <config.h>
-#include <pthread.h>
#include <string.h>
#include <glib.h>
@@ -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 ();
diff --git a/plugins/sa-junk-plugin/em-junk-filter.c b/plugins/sa-junk-plugin/em-junk-filter.c
index ff38f18d6a..df5fdecb0a 100644
--- a/plugins/sa-junk-plugin/em-junk-filter.c
+++ b/plugins/sa-junk-plugin/em-junk-filter.c
@@ -31,7 +31,6 @@
#include <errno.h>
#include <signal.h>
#include <string.h>
-#include <pthread.h>
#include <signal.h>
#include <time.h>
@@ -53,10 +52,10 @@
#define d(x) (camel_debug("junk")?(x):0)
-static pthread_mutex_t em_junk_sa_init_lock = PTHREAD_MUTEX_INITIALIZER;
-static pthread_mutex_t em_junk_sa_report_lock = PTHREAD_MUTEX_INITIALIZER;
-static pthread_mutex_t em_junk_sa_preferred_socket_path_lock = PTHREAD_MUTEX_INITIALIZER;
-static pthread_mutex_t em_junk_sa_spamd_restart_lock = PTHREAD_MUTEX_INITIALIZER;
+G_LOCK_DEFINE_STATIC (init);
+G_LOCK_DEFINE_STATIC (report);
+G_LOCK_DEFINE_STATIC (socket_path);
+G_LOCK_DEFINE_STATIC (spamd_restart);
gint e_plugin_lib_enable (EPlugin *ep, gint enable);
gboolean em_junk_sa_check_junk (EPlugin *ep, EMJunkTarget *target);
@@ -273,7 +272,7 @@ em_junk_sa_test_spamd_running (const gchar *binary, gboolean system)
gint i = 0;
gboolean rv;
- pthread_mutex_lock (&em_junk_sa_preferred_socket_path_lock);
+ G_LOCK (socket_path);
d(fprintf (stderr, "test if spamd is running (system %d) or using socket path %s\n", system, em_junk_sa_get_socket_path ()));
@@ -291,7 +290,7 @@ em_junk_sa_test_spamd_running (const gchar *binary, gboolean system)
d(fprintf (stderr, "result: %d (%s)\n", rv, rv ? "success" : "failed"));
- pthread_mutex_unlock (&em_junk_sa_preferred_socket_path_lock);
+ G_UNLOCK (socket_path);
return rv;
}
@@ -341,7 +340,7 @@ em_junk_sa_run_spamd (const gchar *binary)
gint i;
gboolean rv = FALSE;
- pthread_mutex_lock (&em_junk_sa_preferred_socket_path_lock);
+ G_LOCK (socket_path);
d(fprintf (stderr, "looks like spamd is not running\n"));
@@ -384,7 +383,7 @@ em_junk_sa_run_spamd (const gchar *binary)
rv = TRUE;
}
- pthread_mutex_unlock (&em_junk_sa_preferred_socket_path_lock);
+ G_UNLOCK (socket_path);
return rv;
}
@@ -497,7 +496,7 @@ em_junk_sa_test_spamd (void)
static gboolean
em_junk_sa_is_available (GError **error)
{
- pthread_mutex_lock (&em_junk_sa_init_lock);
+ G_LOCK (init);
if (!em_junk_sa_tested)
em_junk_sa_test_spamassassin ();
@@ -512,7 +511,7 @@ em_junk_sa_is_available (GError **error)
if (!em_junk_sa_allow_tell_tested)
em_junk_sa_test_allow_tell ();
- pthread_mutex_unlock (&em_junk_sa_init_lock);
+ G_UNLOCK (init);
return em_junk_sa_available;
}
@@ -523,7 +522,7 @@ em_junk_sa_check_respawn_too_fast ()
time_t time_now = time (NULL);
gboolean rv;
- pthread_mutex_lock (&em_junk_sa_spamd_restart_lock);
+ G_LOCK (spamd_restart);
if (em_junk_sa_spamd_restarts_count >= SPAMD_RESTARTS_SIZE) {
/* all restarts in last 5 minutes */
@@ -534,7 +533,7 @@ em_junk_sa_check_respawn_too_fast ()
em_junk_sa_spamd_restarts [em_junk_sa_spamd_restarts_count % SPAMD_RESTARTS_SIZE] = time_now;
em_junk_sa_spamd_restarts_count ++;
- pthread_mutex_unlock (&em_junk_sa_spamd_restart_lock);
+ G_UNLOCK (spamd_restart);
d(printf ("em_junk_sa_check_respawn_too_fast: %d\n", rv));
@@ -594,10 +593,10 @@ em_junk_sa_check_junk(EPlugin *ep, EMJunkTarget *target)
if (!em_junk_sa_system_spamd_available) {
argv[i++] = "-U";
- pthread_mutex_lock (&em_junk_sa_preferred_socket_path_lock);
+ G_LOCK (socket_path);
socket_i = i;
argv[i++] = to_free = g_strdup (em_junk_sa_get_socket_path ());
- pthread_mutex_unlock (&em_junk_sa_preferred_socket_path_lock);
+ G_UNLOCK (socket_path);
}
} else {
argv [i++] = "spamassassin";
@@ -615,10 +614,10 @@ em_junk_sa_check_junk(EPlugin *ep, EMJunkTarget *target)
if (em_junk_sa_respawn_spamd ()) {
g_byte_array_set_size (out, 0);
- pthread_mutex_lock (&em_junk_sa_preferred_socket_path_lock);
+ G_LOCK (socket_path);
g_free (to_free);
argv [socket_i] = to_free = g_strdup (em_junk_sa_get_socket_path ());
- pthread_mutex_unlock (&em_junk_sa_preferred_socket_path_lock);
+ G_UNLOCK (socket_path);
rv = pipe_to_sa_full (msg, NULL, argv, 0, 1, out, &target->error) != 0;
} else if (!em_junk_sa_use_spamc)
@@ -706,11 +705,11 @@ em_junk_sa_report_junk (EPlugin *ep, EMJunkTarget *target)
if (no_allow_tell && em_junk_sa_local_only)
argv[4] = "--local";
- pthread_mutex_lock (&em_junk_sa_report_lock);
+ G_LOCK (report);
pipe_to_sa (msg, NULL,
(no_allow_tell ? argv : argv2),
&target->error);
- pthread_mutex_unlock (&em_junk_sa_report_lock);
+ G_UNLOCK (report);
}
}
@@ -743,11 +742,11 @@ em_junk_sa_report_non_junk (EPlugin *ep, EMJunkTarget *target)
if (no_allow_tell && em_junk_sa_local_only)
argv[4] = "--local";
- pthread_mutex_lock (&em_junk_sa_report_lock);
+ G_LOCK (report);
pipe_to_sa (msg, NULL,
(no_allow_tell ? argv : argv2),
&target->error);
- pthread_mutex_unlock (&em_junk_sa_report_lock);
+ G_UNLOCK (report);
}
}
@@ -773,9 +772,9 @@ em_junk_sa_commit_reports (EPlugin *ep)
if (em_junk_sa_local_only)
argv[2] = "--local";
- pthread_mutex_lock (&em_junk_sa_report_lock);
+ G_LOCK (report);
pipe_to_sa (NULL, NULL, argv, NULL);
- pthread_mutex_unlock (&em_junk_sa_report_lock);
+ G_UNLOCK (report);
}
}
@@ -804,10 +803,10 @@ em_junk_sa_setting_notify(GConfClient *gconf, guint cnxn_id, GConfEntry *entry,
else if (!strcmp(tkey, "use_daemon"))
em_junk_sa_use_daemon = gconf_value_get_bool(value);
else if (!strcmp(tkey, "socket_path")) {
- pthread_mutex_lock (&em_junk_sa_preferred_socket_path_lock);
+ G_LOCK (socket_path);
g_free (em_junk_sa_preferred_socket_path);
em_junk_sa_preferred_socket_path = g_strdup (gconf_value_get_string(value));
- pthread_mutex_unlock (&em_junk_sa_preferred_socket_path_lock);
+ G_UNLOCK (socket_path);
}
}
@@ -822,7 +821,7 @@ e_plugin_lib_enable (EPlugin *ep, gint enable)
static void
em_junk_sa_init (void)
{
- pthread_mutex_lock (&em_junk_sa_init_lock);
+ G_LOCK (init);
if (!em_junk_sa_gconf) {
em_junk_sa_gconf = gconf_client_get_default();
@@ -831,10 +830,10 @@ em_junk_sa_init (void)
em_junk_sa_local_only = gconf_client_get_bool (em_junk_sa_gconf, "/apps/evolution/mail/junk/sa/local_only", NULL);
em_junk_sa_use_daemon = gconf_client_get_bool (em_junk_sa_gconf, "/apps/evolution/mail/junk/sa/use_daemon", NULL);
- pthread_mutex_lock (&em_junk_sa_preferred_socket_path_lock);
+ G_LOCK (socket_path);
g_free (em_junk_sa_preferred_socket_path);
em_junk_sa_preferred_socket_path = gconf_client_get_string (em_junk_sa_gconf, "/apps/evolution/mail/junk/sa/socket_path", NULL);
- pthread_mutex_unlock (&em_junk_sa_preferred_socket_path_lock);
+ G_UNLOCK (socket_path);
gconf_client_notify_add(em_junk_sa_gconf, "/apps/evolution/mail/junk/sa",
(GConfClientNotifyFunc)em_junk_sa_setting_notify,
@@ -844,7 +843,7 @@ em_junk_sa_init (void)
em_junk_sa_spamd_gconf_binary = gconf_client_get_string (em_junk_sa_gconf, "/apps/evolution/mail/junk/sa/spamd_binary", NULL);
}
- pthread_mutex_unlock (&em_junk_sa_init_lock);
+ G_UNLOCK (init);
atexit (em_junk_sa_finalize);
}
@@ -852,10 +851,10 @@ em_junk_sa_init (void)
static void
em_junk_sa_kill_spamd (void)
{
- pthread_mutex_lock (&em_junk_sa_preferred_socket_path_lock);
+ G_LOCK (socket_path);
g_free (em_junk_sa_preferred_socket_path);
em_junk_sa_preferred_socket_path = NULL;
- pthread_mutex_unlock (&em_junk_sa_preferred_socket_path_lock);
+ G_UNLOCK (socket_path);
if (em_junk_sa_new_daemon_started) {
gint fd = open (em_junk_sa_spamd_pidfile, O_RDONLY);