[balsa/gtk3] Build with enable-threads
- From: Peter Bloomfield <PeterB src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [balsa/gtk3] Build with enable-threads
- Date: Thu, 21 Feb 2013 02:50:25 +0000 (UTC)
commit 4b842c9bc2ec9b8b1e48928c3f73812ed83f3a7e
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date: Wed Feb 20 20:46:37 2013 -0500
Build with enable-threads
* libbalsa/libbalsa.c (libbalsa_lock_mailbox),
(libbalsa_threads_init), (libbalsa_threads_has_lock): rip out
gdk_threads-related code.
* libbalsa/libbalsa.h: ditto.
* src/main.c (threads_init): ditto.
* libbalsa/imap-server.c (connection_cleanup): not ready for
threads.
* libbalsa/mailbox.c (libbalsa_mailbox_class_init),
(lbm_get_index_entry), (lbm_check_idle): ditto.
* libbalsa/mailbox_local.c (lbm_local_save_tree_idle): ditto
* libbalsa/mailbox_pop3.c: use a thread.
* libbalsa/mailbox_pop3.h: ditto.
* libbalsa/send.c (lbs_process_queue), (libbalsa_process_queue):
* src/main-window.c: ditto.
ChangeLog | 20 +++++++++++++++++
libbalsa/imap-server.c | 4 +-
libbalsa/libbalsa.c | 53 +--------------------------------------------
libbalsa/libbalsa.h | 2 +-
libbalsa/mailbox.c | 12 +++++-----
libbalsa/mailbox_local.c | 4 +-
libbalsa/mailbox_pop3.c | 6 +++++
libbalsa/mailbox_pop3.h | 6 -----
libbalsa/send.c | 4 +-
src/main-window.c | 41 ++++++++++++++++++++--------------
src/main.c | 1 -
11 files changed, 65 insertions(+), 88 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 3af4abf..0ce32d0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2013-02-20 Peter Bloomfield
+
+ Build with enable-threads; check POP3 mail and send messages in
+ threads.
+
+ * libbalsa/libbalsa.c (libbalsa_lock_mailbox),
+ (libbalsa_threads_init), (libbalsa_threads_has_lock): rip out
+ gdk_threads-related code.
+ * libbalsa/libbalsa.h: ditto.
+ * src/main.c (threads_init): ditto.
+ * libbalsa/imap-server.c (connection_cleanup): not ready for
+ threads.
+ * libbalsa/mailbox.c (libbalsa_mailbox_class_init),
+ (lbm_get_index_entry), (lbm_check_idle): ditto.
+ * libbalsa/mailbox_local.c (lbm_local_save_tree_idle): ditto
+ * libbalsa/mailbox_pop3.c: use a thread.
+ * libbalsa/mailbox_pop3.h: ditto.
+ * libbalsa/send.c (lbs_process_queue), (libbalsa_process_queue):
+ * src/main-window.c: ditto.
+
2013-02-16 Peter Bloomfield
* libbalsa/libbalsa-conf.c (lbc_lock), (lbc_unlock): call
diff --git a/libbalsa/imap-server.c b/libbalsa/imap-server.c
index 40786f5..728d0a3 100644
--- a/libbalsa/imap-server.c
+++ b/libbalsa/imap-server.c
@@ -456,7 +456,7 @@ lb_imap_server_cleanup(LibBalsaImapServer * imap_server)
static gboolean connection_cleanup(gpointer ptr)
{
-#ifdef BALSA_USE_THREADS
+#if 0 && defined(BALSA_USE_THREADS)
pthread_t cleanup_thread;
#endif /*BALSA_USE_THREADS */
LibBalsaImapServer *imap_server;
@@ -464,7 +464,7 @@ static gboolean connection_cleanup(gpointer ptr)
g_return_val_if_fail(LIBBALSA_IS_IMAP_SERVER(ptr), FALSE);
imap_server = LIBBALSA_IMAP_SERVER(ptr);
-#ifdef BALSA_USE_THREADS
+#if 0 && defined(BALSA_USE_THREADS)
pthread_create(&cleanup_thread, NULL,
(void *) lb_imap_server_cleanup, imap_server);
pthread_detach(cleanup_thread);
diff --git a/libbalsa/libbalsa.c b/libbalsa/libbalsa.c
index 25ab944..2eebb3f 100644
--- a/libbalsa/libbalsa.c
+++ b/libbalsa/libbalsa.c
@@ -702,18 +702,11 @@ libbalsa_lock_mailbox(LibBalsaMailbox * mailbox)
/* We already have both locks, so we'll just hold on to both of
* them. */
++mailbox->lock;
-#if LIBBALSA_DEBUG_THREADS
- g_message("Avoided temporary gdk_threads_leave!!!");
-#endif /* LIBBALSA_DEBUG_THREADS */
return;
}
while (thread_id == libbalsa_threads_id) {
++count;
-#if LIBBALSA_DEBUG_THREADS
- g_message("Temporary gdk_threads_leave!!!");
-#endif /* LIBBALSA_DEBUG_THREADS */
- gdk_threads_leave();
}
pthread_mutex_lock(&mailbox_mutex);
@@ -728,13 +721,6 @@ libbalsa_lock_mailbox(LibBalsaMailbox * mailbox)
mailbox->thread_id = thread_id;
pthread_mutex_unlock(&mailbox_mutex);
-
- while (--count >= 0) {
- gdk_threads_enter();
-#if LIBBALSA_DEBUG_THREADS
- g_message("...and gdk_threads_enter!!!");
-#endif /* LIBBALSA_DEBUG_THREADS */
- }
}
void
@@ -764,46 +750,11 @@ libbalsa_unlock_mailbox(LibBalsaMailbox * mailbox)
static pthread_mutex_t libbalsa_threads_mutex;
static guint libbalsa_threads_lock;
-static void
-libbalsa_threads_enter(void)
-{
- pthread_t self;
-
- self = pthread_self();
-
- if (self != libbalsa_threads_id) {
- pthread_mutex_lock(&libbalsa_threads_mutex);
- libbalsa_threads_id = self;
- }
- ++libbalsa_threads_lock;
-}
-
-static void
-libbalsa_threads_leave(void)
-{
- pthread_t self;
-
- self = pthread_self();
-
- if (libbalsa_threads_lock == 0 || self != libbalsa_threads_id) {
- g_warning("%s: Not holding gdk lock!!!", __func__);
- return;
- }
-
- if (--libbalsa_threads_lock == 0) {
- if (self != main_thread_id)
- gdk_display_flush(gdk_display_get_default());
- libbalsa_threads_id = 0;
- pthread_mutex_unlock(&libbalsa_threads_mutex);
- }
-}
void
libbalsa_threads_init(void)
{
pthread_mutex_init(&libbalsa_threads_mutex, NULL);
- gdk_threads_set_lock_functions(G_CALLBACK(libbalsa_threads_enter),
- G_CALLBACK(libbalsa_threads_leave));
}
void
@@ -815,8 +766,8 @@ libbalsa_threads_destroy(void)
gboolean
libbalsa_threads_has_lock(void)
{
- return libbalsa_threads_lock > 0
- && libbalsa_threads_id == pthread_self();
+ return TRUE || (libbalsa_threads_lock > 0
+ && libbalsa_threads_id == pthread_self());
}
#endif /* BALSA_USE_THREADS */
diff --git a/libbalsa/libbalsa.h b/libbalsa/libbalsa.h
index 516cd44..873e072 100644
--- a/libbalsa/libbalsa.h
+++ b/libbalsa/libbalsa.h
@@ -149,9 +149,9 @@ gboolean libbalsa_threads_has_lock(void);
#else
#define libbalsa_am_i_subthread() FALSE
#define libbalsa_threads_has_lock() TRUE
+#endif /* BALSA_USE_THREADS */
#define gdk_threads_enter()
#define gdk_threads_leave()
-#endif /* BALSA_USE_THREADS */
void libbalsa_message(const char *fmt, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 2)))
diff --git a/libbalsa/mailbox.c b/libbalsa/mailbox.c
index bf727e5..d8648c8 100644
--- a/libbalsa/mailbox.c
+++ b/libbalsa/mailbox.c
@@ -64,7 +64,7 @@ static void libbalsa_mailbox_real_load_config(LibBalsaMailbox * mailbox,
const gchar * group);
static gboolean libbalsa_mailbox_real_close_backend (LibBalsaMailbox *
mailbox);
-#if BALSA_USE_THREADS
+#ifdef BALSA_USE_THREADS
static void libbalsa_mailbox_real_lock_store(LibBalsaMailbox * mailbox,
gboolean lock);
#endif /* BALSA_USE_THREADS */
@@ -233,7 +233,7 @@ libbalsa_mailbox_class_init(LibBalsaMailboxClass * klass)
klass->close_backend = libbalsa_mailbox_real_close_backend;
klass->total_messages = NULL;
klass->duplicate_msgnos = NULL;
-#if BALSA_USE_THREADS
+#ifdef BALSA_USE_THREADS
klass->lock_store = libbalsa_mailbox_real_lock_store;
#endif /* BALSA_USE_THREADS */
}
@@ -367,7 +367,7 @@ lbm_index_entry_populate_from_msg(LibBalsaMailboxIndexEntry * entry,
libbalsa_mailbox_msgno_changed(msg->mailbox, msg->msgno);
}
-#ifdef BALSA_USE_THREADS
+#if 0 && defined(BALSA_USE_THREADS)
static LibBalsaMailboxIndexEntry*
lbm_index_entry_new_pending(void)
{
@@ -2902,7 +2902,6 @@ mbox_model_get_path(GtkTreeModel * tree_model, GtkTreeIter * iter)
static GdkPixbuf *status_icons[LIBBALSA_MESSAGE_STATUS_ICONS_NUM];
static GdkPixbuf *attach_icons[LIBBALSA_MESSAGE_ATTACH_ICONS_NUM];
-#ifdef BALSA_USE_THREADS
/* Protects access to mailbox->msgnos_pending; may be locked
* with or without the gdk lock, so WE MUST NOT GRAB THE GDK LOCK WHILE
* HOLDING IT. */
@@ -2916,6 +2915,7 @@ lbm_get_index_entry_expunged_cb(LibBalsaMailbox * mailbox, guint seqno)
pthread_mutex_unlock(&get_index_entry_lock);
}
+#if 0 && defined(BALSA_USE_THREADS)
static void
lbm_get_index_entry_real(LibBalsaMailbox * mailbox)
{
@@ -2967,7 +2967,7 @@ lbm_get_index_entry(LibBalsaMailbox * lmm, guint msgno)
g_ptr_array_set_size(lmm->mindex, msgno);
entry = g_ptr_array_index(lmm->mindex, msgno - 1);
-#ifdef BALSA_USE_THREADS
+#if 0 && defined(BALSA_USE_THREADS)
if (entry)
return entry->idle_pending ? NULL : entry;
@@ -4274,7 +4274,7 @@ lbm_check_real(LibBalsaMailbox * mailbox)
static gboolean
lbm_check_idle(LibBalsaMailbox * mailbox)
{
-#ifdef BALSA_USE_THREADS
+#if 0 && defined(BALSA_USE_THREADS)
pthread_t check_thread;
pthread_create(&check_thread, NULL, (void *) lbm_check_real, mailbox);
diff --git a/libbalsa/mailbox_local.c b/libbalsa/mailbox_local.c
index 5dbb08f..083090a 100644
--- a/libbalsa/mailbox_local.c
+++ b/libbalsa/mailbox_local.c
@@ -685,7 +685,7 @@ lbm_local_save_tree_real(LibBalsaMailboxLocal * local)
static gboolean
lbm_local_save_tree_idle(LibBalsaMailboxLocal * local)
{
-#ifdef BALSA_USE_THREADS
+#if 0 && defined(BALSA_USE_THREADS)
pthread_t save_tree_thread;
pthread_create(&save_tree_thread, NULL,
@@ -2117,7 +2117,7 @@ lbm_local_sync_real(LibBalsaMailboxLocal * local)
static gboolean
lbm_local_sync_idle(LibBalsaMailboxLocal * local)
{
-#ifdef BALSA_USE_THREADS
+#if 0 && defined(BALSA_USE_THREADS)
pthread_t sync_thread;
pthread_create(&sync_thread, NULL, (void *) lbm_local_sync_real, local);
diff --git a/libbalsa/mailbox_pop3.c b/libbalsa/mailbox_pop3.c
index 8f84b0d..16575cc 100644
--- a/libbalsa/mailbox_pop3.c
+++ b/libbalsa/mailbox_pop3.c
@@ -51,6 +51,12 @@ enum {
};
static LibBalsaMailboxClass *parent_class = NULL;
+struct _LibBalsaMailboxPop3Class {
+ LibBalsaMailboxRemoteClass klass;
+
+ void (*config_changed) (LibBalsaMailboxPop3* mailbox);
+};
+
static void libbalsa_mailbox_pop3_finalize(GObject * object);
static void libbalsa_mailbox_pop3_class_init(LibBalsaMailboxPop3Class *
klass);
diff --git a/libbalsa/mailbox_pop3.h b/libbalsa/mailbox_pop3.h
index 6a5b2f7..2054e39 100644
--- a/libbalsa/mailbox_pop3.h
+++ b/libbalsa/mailbox_pop3.h
@@ -54,12 +54,6 @@ struct _LibBalsaMailboxPop3 {
* they do not. */
};
-struct _LibBalsaMailboxPop3Class {
- LibBalsaMailboxRemoteClass klass;
-
- void (*config_changed) (LibBalsaMailboxPop3* mailbox);
-};
-
LibBalsaMailboxPop3 *libbalsa_mailbox_pop3_new(void);
void libbalsa_mailbox_pop3_set_inbox(LibBalsaMailbox *mailbox,
LibBalsaMailbox *inbox);
diff --git a/libbalsa/send.c b/libbalsa/send.c
index 8ae3c44..9343518 100644
--- a/libbalsa/send.c
+++ b/libbalsa/send.c
@@ -907,7 +907,7 @@ lbs_process_queue(LibBalsaMailbox * outbox, LibBalsaFccboxFinder finder,
send_message_info=send_message_info_new(outbox, session, debug);
-#ifdef BALSA_USE_THREADS
+#if defined(BALSA_USE_THREADS)
sending_threads++;
pthread_create(&send_mail, NULL,
(void *) &balsa_send_message_real, send_message_info);
@@ -1294,7 +1294,7 @@ libbalsa_process_queue(LibBalsaMailbox* outbox, LibBalsaFccboxFinder finder,
send_message_info=send_message_info_new(outbox, finder, debug);
-#ifdef BALSA_USE_THREADS
+#if 0 && defined(BALSA_USE_THREADS)
pthread_create(&send_mail, NULL,
(void *) &balsa_send_message_real, send_message_info);
diff --git a/src/main-window.c b/src/main-window.c
index 481d5b2..54629ae 100644
--- a/src/main-window.c
+++ b/src/main-window.c
@@ -138,10 +138,10 @@ static gboolean bw_idle_cb(BalsaWindow * window);
static void bw_check_mailbox_list(BalsaWindow * window, GList * list);
-static gboolean bw_mailbox_check_func(GtkTreeModel * model,
- GtkTreePath * path,
- GtkTreeIter * iter,
- GSList ** list);
+static gboolean bw_add_mbox_to_checklist(GtkTreeModel * model,
+ GtkTreePath * path,
+ GtkTreeIter * iter,
+ GSList ** list);
static gboolean bw_imap_check_test(const gchar * path);
static void bw_enable_mailbox_menus(BalsaWindow * window, BalsaIndex * index);
@@ -2410,7 +2410,7 @@ bw_real_open_mbnode(BalsaWindow *window, BalsaMailboxNode * mbnode,
balsa_index_scroll_on_open(index);
}
-#ifdef BALSA_USE_THREADS
+#if 0 && defined(BALSA_USE_THREADS)
static pthread_mutex_t open_lock = PTHREAD_MUTEX_INITIALIZER;
struct bw_open_mbnode_info {
@@ -2456,7 +2456,7 @@ balsa_window_real_open_mbnode(BalsaWindow * window,
BalsaMailboxNode * mbnode,
gboolean set_current)
{
-#ifdef BALSA_USE_THREADS
+#if 0 && defined(BALSA_USE_THREADS)
struct bw_open_mbnode_info *info;
static GPtrArray *info_array;
@@ -2795,8 +2795,8 @@ bw_check_mailbox_list(BalsaWindow * window, GList * mailbox_list)
/*Callback to check a mailbox in a balsa-mblist */
static gboolean
-bw_mailbox_check_func(GtkTreeModel * model, GtkTreePath * path,
- GtkTreeIter * iter, GSList ** list)
+bw_add_mbox_to_checklist(GtkTreeModel * model, GtkTreePath * path,
+ GtkTreeIter * iter, GSList ** list)
{
BalsaMailboxNode *mbnode;
LibBalsaMailbox *mailbox;
@@ -2829,6 +2829,9 @@ bw_imap_check_test(const gchar * path)
#if BALSA_USE_THREADS
static void
+bw_mailbox_check(LibBalsaMailbox * mailbox, BalsaWindow * window);
+
+static void
bw_progress_dialog_destroy_cb(GtkWidget * widget, gpointer data)
{
progress_dialog = NULL;
@@ -2920,12 +2923,12 @@ void
check_new_messages_real(BalsaWindow * window, int type)
{
GSList *list;
-#ifdef BALSA_USE_THREADS
+#if defined(BALSA_USE_THREADS)
struct check_messages_thread_info *info;
#endif
list = NULL;
-#ifdef BALSA_USE_THREADS
+#if defined(BALSA_USE_THREADS)
/* Only Run once -- If already checking mail, return. */
pthread_mutex_lock(&checking_mail_lock);
if (checking_mail) {
@@ -2949,9 +2952,6 @@ check_new_messages_real(BalsaWindow * window, int type)
(balsa_app.pwindow_option == UNTILCLOSED && progress_dialog)))
ensure_check_mail_dialog(window);
- gtk_tree_model_foreach(GTK_TREE_MODEL(balsa_app.mblist_tree_store),
- (GtkTreeModelForeachFunc) bw_mailbox_check_func,
- &list);
/* initiate threads */
info = g_new(struct check_messages_thread_info, 1);
@@ -2965,6 +2965,13 @@ check_new_messages_real(BalsaWindow * window, int type)
* reclaimed as soon as the thread exits
*/
pthread_detach(get_mail_thread);
+
+ gtk_tree_model_foreach(GTK_TREE_MODEL(balsa_app.mblist_tree_store),
+ (GtkTreeModelForeachFunc) bw_add_mbox_to_checklist,
+ &list);
+ g_slist_foreach(list, (GFunc) bw_mailbox_check, window);
+ g_slist_foreach(list, (GFunc) g_object_unref, NULL);
+ g_slist_free(list);
#else
if (window)
@@ -2973,7 +2980,7 @@ check_new_messages_real(BalsaWindow * window, int type)
bw_check_mailbox_list(window, balsa_app.inbox_input);
gtk_tree_model_foreach(GTK_TREE_MODEL(balsa_app.mblist_tree_store),
- (GtkTreeModelForeachFunc) bw_mailbox_check_func,
+ (GtkTreeModelForeachFunc) bw_add_mbox_to_checklist,
&list);
g_slist_foreach(list, (GFunc) bw_mailbox_check, window);
g_slist_foreach(list, (GFunc) g_object_unref, NULL);
@@ -3099,7 +3106,7 @@ bw_message_print_cb(GtkAction * action, gpointer data)
}
/* this one is called only in the threaded code */
-#ifdef BALSA_USE_THREADS
+#if defined(BALSA_USE_THREADS)
static void
bw_mailbox_check(LibBalsaMailbox * mailbox, BalsaWindow * window)
{
@@ -3614,7 +3621,7 @@ bw_change_connection_status_thread(void *arg)
return NULL;
}
-#ifndef BALSA_USE_THREADS
+#if !(0 && defined(BALSA_USE_THREADS))
static gboolean
bw_change_connection_status_idle(gpointer data)
{
@@ -3672,7 +3679,7 @@ bw_nm_client_state_changed_cb(GObject * gobject, GParamSpec * pspec,
is_connected = (new_state == NM_STATE_CONNECTED);
if (is_connected || old_state == NM_STATE_CONNECTED) {
-#if BALSA_USE_THREADS
+#if 0 && defined(BALSA_USE_THREADS)
pthread_t thread_id;
if (pthread_create(&thread_id, NULL,
diff --git a/src/main.c b/src/main.c
index 7c4676f..3c7864f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -265,7 +265,6 @@ threads_init(void)
g_type_init();
libbalsa_threads_init();
- gdk_threads_init();
pthread_mutex_init(&send_messages_lock, NULL);
if (pipe(mail_thread_pipes) < 0) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]