[balsa/gtk3] Update mailbox in idle callbacks



commit b007506b0290c6c2ffb60e916268d57e241d3183
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Fri Jun 8 13:34:25 2012 -0400

    Update mailbox in idle callbacks
    
    	* libbalsa/mailbox.c (lbm_check_and_sort),
    	(lbm_set_threading_idle_cb), (lbm_set_threading): sort in an
    	idle callback instead of subthread.
    	* libbalsa/mailbox_local.c (lbml_set_threading),
    	(lbml_set_threading_idle_cb),
    	(libbalsa_mailbox_local_set_threading): set threading type in an
    	idle callback instead of subthread.

 ChangeLog                |   10 ++++++++
 libbalsa/mailbox.c       |   38 ++++++++++++++++++++++++++-----
 libbalsa/mailbox_local.c |   56 +++++++++++++++++++++++++++++++++++++--------
 3 files changed, 88 insertions(+), 16 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 0b16b3a..11629cb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2012-06-08  Peter Bloomfield
+
+	* libbalsa/mailbox.c (lbm_check_and_sort),
+	(lbm_set_threading_idle_cb), (lbm_set_threading): sort in an
+	idle callback instead of subthread.
+	* libbalsa/mailbox_local.c (lbml_set_threading),
+	(lbml_set_threading_idle_cb),
+	(libbalsa_mailbox_local_set_threading): set threading type in an
+	idle callback instead of subthread.
+
 2012-06-07  Peter Bloomfield
 
 	* src/main.c (progress_set_text), (progress_set_text_idle_cb),
diff --git a/libbalsa/mailbox.c b/libbalsa/mailbox.c
index 5572221..ea48acc 100644
--- a/libbalsa/mailbox.c
+++ b/libbalsa/mailbox.c
@@ -2342,6 +2342,26 @@ libbalsa_mailbox_can_do(LibBalsaMailbox *mailbox,
 
 
 static void lbm_sort(LibBalsaMailbox * mbox, GNode * parent);
+
+static void
+lbm_check_and_sort(LibBalsaMailbox * mailbox)
+{
+    if (mailbox->msg_tree)
+        lbm_sort(mailbox, mailbox->msg_tree);
+
+    libbalsa_mailbox_changed(mailbox);
+}
+
+#ifdef BALSA_USE_THREADS
+static gboolean
+lbm_set_threading_idle_cb(LibBalsaMailbox * mailbox)
+{
+    lbm_check_and_sort(mailbox);
+    g_object_unref(mailbox);
+    return FALSE;
+}
+#endif                          /* BALSA_USE_THREADS */
+
 static gboolean
 lbm_set_threading(LibBalsaMailbox * mailbox,
                   LibBalsaMailboxThreadingType thread_type)
@@ -2351,12 +2371,18 @@ lbm_set_threading(LibBalsaMailbox * mailbox,
 
     LIBBALSA_MAILBOX_GET_CLASS(mailbox)->set_threading(mailbox,
                                                        thread_type);
-    gdk_threads_enter();
-    if (mailbox->msg_tree)
-        lbm_sort(mailbox, mailbox->msg_tree);
-
-    libbalsa_mailbox_changed(mailbox);
-    gdk_threads_leave();
+#ifdef BALSA_USE_THREADS
+    if (libbalsa_am_i_subthread()) {
+        gdk_threads_add_idle((GSourceFunc) lbm_set_threading_idle_cb,
+                             g_object_ref(mailbox));
+    } else {
+        gdk_threads_enter();
+        lbm_check_and_sort(mailbox);
+        gdk_threads_leave();
+    }
+#else                           /* BALSA_USE_THREADS */
+    lbm_check_and_sort(mailbox);
+#endif                          /* BALSA_USE_THREADS */
 
     return TRUE;
 }
diff --git a/libbalsa/mailbox_local.c b/libbalsa/mailbox_local.c
index 6486612..62733e1 100644
--- a/libbalsa/mailbox_local.c
+++ b/libbalsa/mailbox_local.c
@@ -1067,6 +1067,37 @@ libbalsa_mailbox_local_set_threading_info(LibBalsaMailboxLocal * local)
 }
 
 static void
+lbml_set_threading(LibBalsaMailbox * mailbox,
+                   LibBalsaMailboxThreadingType thread_type)
+{
+    switch (thread_type) {
+    case LB_MAILBOX_THREADING_JWZ:
+        lbml_threading_jwz(mailbox);
+        break;
+    case LB_MAILBOX_THREADING_FLAT:
+    case LB_MAILBOX_THREADING_SIMPLE:
+        lbml_threading_simple(mailbox, thread_type);
+        break;
+    }
+}
+
+#ifdef BALSA_USE_THREADS
+typedef struct {
+    LibBalsaMailbox *mailbox;
+    LibBalsaMailboxThreadingType thread_type;
+} LbmlSetThreadingInfo;
+
+static gboolean
+lbml_set_threading_idle_cb(LbmlSetThreadingInfo * info)
+{
+    lbml_set_threading(info->mailbox, info->thread_type);
+    g_object_unref(info->mailbox);
+    g_slice_free(LbmlSetThreadingInfo, info);
+    return FALSE;
+}
+#endif                          /* BALSA_USE_THREADS */
+
+static void
 libbalsa_mailbox_local_set_threading(LibBalsaMailbox * mailbox,
                                      LibBalsaMailboxThreadingType
                                      thread_type)
@@ -1108,17 +1139,22 @@ libbalsa_mailbox_local_set_threading(LibBalsaMailbox * mailbox,
             return;
     }
 
-    gdk_threads_enter();
-    switch (thread_type) {
-    case LB_MAILBOX_THREADING_JWZ:
-        lbml_threading_jwz(mailbox);
-        break;
-    case LB_MAILBOX_THREADING_FLAT:
-    case LB_MAILBOX_THREADING_SIMPLE:
-        lbml_threading_simple(mailbox, thread_type);
-        break;
+#ifdef BALSA_USE_THREADS
+    if (libbalsa_am_i_subthread()) {
+        LbmlSetThreadingInfo *info;
+
+        info = g_slice_new(LbmlSetThreadingInfo);
+        info->mailbox = g_object_ref(mailbox);
+        info->thread_type = thread_type;
+        gdk_threads_add_idle((GSourceFunc) lbml_set_threading_idle_cb, info);
+    } else {
+        gdk_threads_enter();
+        lbml_set_threading(mailbox, thread_type);
+        gdk_threads_leave();
     }
-    gdk_threads_leave();
+#else                           /* BALSA_USE_THREADS */
+    lbml_set_threading(mailbox, thread_type);
+#endif                          /* BALSA_USE_THREADS */
 #if defined(DEBUG_LOADING_AND_THREADING)
     printf("after threading time=%lu\n", (unsigned long) time(NULL));
 #endif



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]