[balsa/gtk3] Re-enable mailbox check in a subthread
- From: Peter Bloomfield <PeterB src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [balsa/gtk3] Re-enable mailbox check in a subthread
- Date: Sat, 2 Mar 2013 12:01:07 +0000 (UTC)
commit 558604fef26537cabd0484cefda7f45b822e6c5c
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date: Sat Mar 2 07:00:46 2013 -0500
Re-enable mailbox check in a subthread
* libbalsa/mailbox.c (libbalsa_mailbox_progress_notify),
(libbalsa_mailbox_msgno_inserted),
(libbalsa_mailbox_msgno_removed),
(libbalsa_mailbox_unlink_and_prepend), (lbm_set_msg_tree):
insert subthread warnings.
(lbm_check_idle): check mailbox in a subthread.
* libbalsa/mailbox_local.c (lbml_load_messages_idle_cb),
(libbalsa_mailbox_local_load_messages): load messages in the
main thread, in an idle callback;
(libbalsa_mailbox_local_finalize): remove any pending idle call.
* libbalsa/mailbox_local.h: new member of LibBalsaMailboxLocal
for the idle id.
ChangeLog | 17 +++++++++++++++++
libbalsa/mailbox.c | 18 +++++++++---------
libbalsa/mailbox_local.c | 45 +++++++++++++++++++++++++++++++++++++++------
libbalsa/mailbox_local.h | 1 +
4 files changed, 66 insertions(+), 15 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index f53cd50..2b8843e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2013-03-02 Peter Bloomfield
+
+ Re-enable mailbox check in a subthread
+
+ * libbalsa/mailbox.c (libbalsa_mailbox_progress_notify),
+ (libbalsa_mailbox_msgno_inserted),
+ (libbalsa_mailbox_msgno_removed),
+ (libbalsa_mailbox_unlink_and_prepend), (lbm_set_msg_tree):
+ insert subthread warnings.
+ (lbm_check_idle): check mailbox in a subthread.
+ * libbalsa/mailbox_local.c (lbml_load_messages_idle_cb),
+ (libbalsa_mailbox_local_load_messages): load messages in the
+ main thread, in an idle callback;
+ (libbalsa_mailbox_local_finalize): remove any pending idle call.
+ * libbalsa/mailbox_local.h: new member of LibBalsaMailboxLocal
+ for the idle id.
+
2013-03-01 Peter Bloomfield
* libbalsa/mailbox.h: idle id is guint, not gulong.
diff --git a/libbalsa/mailbox.c b/libbalsa/mailbox.c
index f2b2c35..1ce89f3 100644
--- a/libbalsa/mailbox.c
+++ b/libbalsa/mailbox.c
@@ -689,6 +689,7 @@ libbalsa_mailbox_progress_notify(LibBalsaMailbox * mailbox,
g_return_if_fail(mailbox != NULL);
g_return_if_fail(LIBBALSA_IS_MAILBOX(mailbox));
+ /* OK to emit in a subthread, because the handler expects it. */
g_signal_emit(G_OBJECT(mailbox),
libbalsa_mailbox_signals[PROGRESS_NOTIFY],
0, type, prog, tot, msg);
@@ -1354,8 +1355,6 @@ libbalsa_mailbox_msgno_inserted(LibBalsaMailbox *mailbox, guint seqno,
GtkTreePath *path;
GSList **unthreaded;
- if (!libbalsa_threads_has_lock())
- g_warning("Thread is not holding gdk lock");
if (!mailbox->msg_tree)
return;
#undef SANITY_CHECK
@@ -1365,6 +1364,7 @@ libbalsa_mailbox_msgno_inserted(LibBalsaMailbox *mailbox, guint seqno,
GUINT_TO_POINTER(seqno)));
#endif
+ gdk_threads_enter();
/* Insert node into the message tree before getting path. */
iter.user_data = g_node_new(GUINT_TO_POINTER(seqno));
iter.stamp = mailbox->stamp;
@@ -1386,6 +1386,7 @@ libbalsa_mailbox_msgno_inserted(LibBalsaMailbox *mailbox, guint seqno,
g_slist_prepend(*unthreaded, GUINT_TO_POINTER(seqno));
mailbox->msg_tree_changed = TRUE;
+ gdk_threads_leave();
}
static void
@@ -1444,10 +1445,10 @@ libbalsa_mailbox_msgno_removed(LibBalsaMailbox * mailbox, guint seqno)
GNode *child;
GNode *parent;
+ gdk_threads_enter();
g_signal_emit(mailbox, libbalsa_mailbox_signals[MESSAGE_EXPUNGED],
0, seqno);
- gdk_threads_enter();
if (!mailbox->msg_tree) {
gdk_threads_leave();
return;
@@ -3784,14 +3785,13 @@ libbalsa_mailbox_unlink_and_prepend(LibBalsaMailbox * mailbox,
GtkTreePath *path;
GNode *current_parent;
- if (!libbalsa_threads_has_lock())
- g_warning("Thread is not holding gdk lock");
g_return_if_fail(node != NULL);
g_return_if_fail(parent != node);
#ifdef SANITY_CHECK
g_return_if_fail(!parent || !g_node_is_ancestor(node, parent));
#endif
+ gdk_threads_enter();
iter.stamp = mailbox->stamp;
path = mbox_model_get_path_helper(node, mailbox->msg_tree);
@@ -3841,6 +3841,7 @@ libbalsa_mailbox_unlink_and_prepend(LibBalsaMailbox * mailbox,
mailbox->msg_tree_changed = TRUE;
}
+ gdk_threads_leave();
}
struct lbm_update_msg_tree_info {
@@ -3962,14 +3963,12 @@ lbm_set_msg_tree(LibBalsaMailbox * mailbox)
GNode *node;
GtkTreePath *path;
- if (!libbalsa_threads_has_lock())
- g_warning("Thread is not holding gdk lock");
-
iter.stamp = ++mailbox->stamp;
if (!mailbox->msg_tree)
return;
+ gdk_threads_enter();
path = gtk_tree_path_new();
gtk_tree_path_down(path);
@@ -3986,6 +3985,7 @@ lbm_set_msg_tree(LibBalsaMailbox * mailbox)
}
gtk_tree_path_free(path);
+ gdk_threads_leave();
}
void
@@ -4313,7 +4313,7 @@ lbm_check_real(LibBalsaMailbox * mailbox)
static gboolean
lbm_check_idle(LibBalsaMailbox * mailbox)
{
-#if 0 && defined(BALSA_USE_THREADS)
+#if 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 0066974..30ea057 100644
--- a/libbalsa/mailbox_local.c
+++ b/libbalsa/mailbox_local.c
@@ -394,6 +394,11 @@ libbalsa_mailbox_local_finalize(GObject * object)
ml->threading_info = NULL;
}
+ if (ml->load_messages_id) {
+ g_source_remove(ml->load_messages_id);
+ ml->load_messages_id = 0;
+ }
+
if (G_OBJECT_CLASS(parent_class)->finalize)
G_OBJECT_CLASS(parent_class)->finalize(object);
}
@@ -1010,10 +1015,16 @@ libbalsa_mailbox_local_cache_message(LibBalsaMailboxLocal * local,
info->sender = g_strdup("");
}
-void
-libbalsa_mailbox_local_load_messages(LibBalsaMailbox *mailbox,
- guint msgno)
+typedef struct {
+ LibBalsaMailbox *mailbox;
+ guint msgno;
+} LbmlLoadMessagesInfo;
+
+static gboolean
+lbml_load_messages_idle_cb(LbmlLoadMessagesInfo * info)
{
+ LibBalsaMailbox *mailbox = info->mailbox;
+ guint msgno = info->msgno;
guint new_messages;
LibBalsaMailboxLocal *local;
guint lastno;
@@ -1021,14 +1032,12 @@ libbalsa_mailbox_local_load_messages(LibBalsaMailbox *mailbox,
LibBalsaMailboxLocalMessageInfo *(*get_info) (LibBalsaMailboxLocal *,
guint);
- g_return_if_fail(LIBBALSA_IS_MAILBOX_LOCAL(mailbox));
-
gdk_threads_enter();
if (!mailbox->msg_tree) {
/* Mailbox is closed, or no view has been created. */
gdk_threads_leave();
- return;
+ return FALSE;
}
local = (LibBalsaMailboxLocal *) mailbox;
@@ -1054,6 +1063,30 @@ libbalsa_mailbox_local_load_messages(LibBalsaMailbox *mailbox,
mailbox->
unread_messages > 0);
}
+
+ local->load_messages_id = 0;
+ return FALSE;
+}
+
+void
+libbalsa_mailbox_local_load_messages(LibBalsaMailbox *mailbox,
+ guint msgno)
+{
+ LbmlLoadMessagesInfo *info;
+ LibBalsaMailboxLocal *local;
+
+ g_return_if_fail(LIBBALSA_IS_MAILBOX_LOCAL(mailbox));
+ local = (LibBalsaMailboxLocal *) mailbox;
+ if (local->load_messages_id)
+ return;
+
+ info = g_new(LbmlLoadMessagesInfo, 1);
+ info->mailbox = mailbox;
+ info->msgno = msgno;
+ local->load_messages_id =
+ g_idle_add_full(G_PRIORITY_DEFAULT_IDLE,
+ (GSourceFunc) lbml_load_messages_idle_cb, info,
+ g_free);
}
/*
diff --git a/libbalsa/mailbox_local.h b/libbalsa/mailbox_local.h
index 55662b9..591fb51 100644
--- a/libbalsa/mailbox_local.h
+++ b/libbalsa/mailbox_local.h
@@ -70,6 +70,7 @@ struct _LibBalsaMailboxLocal {
* average the syncing time for mailbox. */
guint thread_id; /* id of the idle mailbox thread job */
guint save_tree_id; /* id of the idle mailbox save-tree job */
+ guint load_messages_id; /* id of the idle load-messages job */
GPtrArray *threading_info;
LibBalsaMailboxLocalPool message_pool[LBML_POOL_SIZE];
guint pool_seqno;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]