[balsa/gtk3] Queue config syncs instead of syncing immediately



commit 09f15b24b5394757e39107d93b5db6f06b5ae5f4
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Sat Mar 16 13:47:05 2013 -0400

    Queue config syncs instead of syncing immediately
    
        * libbalsa/libbalsa-conf.c (libbalsa_conf_sync_idle_cb),
        (libbalsa_conf_queue_sync): new API libbalsa_conf_queue_sync.
        * libbalsa/libbalsa-conf.h: ditto.
        * src/ab-main.c (address_book_change), (file_delete_cb): use it.
        * src/save-restore.c (config_address_book_save),
        (config_address_book_delete), (config_mailbox_add),
        (config_folder_add), (config_mailbox_delete),
        (config_folder_delete), (config_mailbox_update),
        (config_folder_update), (config_filters_save),
        (config_mailbox_filters_save): ditto.

 ChangeLog                |   16 ++++++++++++++++
 libbalsa/libbalsa-conf.c |   34 ++++++++++++++++++++++++++++++++++
 libbalsa/libbalsa-conf.h |    1 +
 src/ab-main.c            |    4 ++--
 src/save-restore.c       |   22 +++++++++++-----------
 5 files changed, 64 insertions(+), 13 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 97e739d..2e08561 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,21 @@
 2013-03-16  Peter Bloomfield
 
+       Queue config syncs instead of syncing immediately, except on
+       exit cleanup
+
+       * libbalsa/libbalsa-conf.c (libbalsa_conf_sync_idle_cb),
+       (libbalsa_conf_queue_sync): new API libbalsa_conf_queue_sync.
+       * libbalsa/libbalsa-conf.h: ditto.
+       * src/ab-main.c (address_book_change), (file_delete_cb): use it.
+       * src/save-restore.c (config_address_book_save),
+       (config_address_book_delete), (config_mailbox_add),
+       (config_folder_add), (config_mailbox_delete),
+       (config_folder_delete), (config_mailbox_update),
+       (config_folder_update), (config_filters_save),
+       (config_mailbox_filters_save): ditto.
+
+2013-03-16  Peter Bloomfield
+
        * src/main-window.c: do not leak object refs on error.
 
 2013-03-16  Peter Bloomfield
diff --git a/libbalsa/libbalsa-conf.c b/libbalsa/libbalsa-conf.c
index 7fbf0ac..4164c71 100644
--- a/libbalsa/libbalsa-conf.c
+++ b/libbalsa/libbalsa-conf.c
@@ -544,3 +544,37 @@ libbalsa_conf_sync(void)
     lbc_sync(&lbc_conf_priv);
     lbc_unlock();
 }
+
+static guint lbc_sync_idle_id;
+G_LOCK_DEFINE_STATIC(lbc_sync_idle_id);
+
+static gboolean
+libbalsa_conf_sync_idle_cb(gpointer data)
+{
+    G_LOCK(lbc_sync_idle_id);
+#if DEBUG
+    g_print("%s id %d, will be cleared\n", __func__, lbc_sync_idle_id);
+#endif                          /* DEBUG */
+    if (lbc_sync_idle_id) {
+        g_source_remove(lbc_sync_idle_id);
+        lbc_sync_idle_id = 0;
+    }
+    G_UNLOCK(lbc_sync_idle_id);
+    libbalsa_conf_sync();
+}
+
+void
+libbalsa_conf_queue_sync(void)
+{
+    G_LOCK(lbc_sync_idle_id);
+#if DEBUG
+    g_print("%s id %d, will be set if zero\n", __func__, lbc_sync_idle_id);
+#endif                          /* DEBUG */
+    if (!lbc_sync_idle_id)
+        lbc_sync_idle_id =
+            g_idle_add((GSourceFunc) libbalsa_conf_sync_idle_cb, NULL);
+#if DEBUG
+    g_print("%s id now %d\n", __func__, lbc_sync_idle_id);
+#endif                          /* DEBUG */
+    G_UNLOCK(lbc_sync_idle_id);
+}
diff --git a/libbalsa/libbalsa-conf.h b/libbalsa/libbalsa-conf.h
index 99521ac..81c5db6 100644
--- a/libbalsa/libbalsa-conf.h
+++ b/libbalsa/libbalsa-conf.h
@@ -121,5 +121,6 @@ void libbalsa_conf_get_vector_with_default   (const char *path,
 
 void libbalsa_conf_drop_all                  (void);
 void libbalsa_conf_sync                      (void);
+void libbalsa_conf_queue_sync                (void);
 
 #endif                          /* __LIBCONFIG_H__ */
diff --git a/src/ab-main.c b/src/ab-main.c
index ecf3655..7c4e474 100644
--- a/src/ab-main.c
+++ b/src/ab-main.c
@@ -347,7 +347,7 @@ address_book_change(LibBalsaAddressBook * address_book, gboolean append)
     libbalsa_address_book_save_config(address_book, group);
     g_free(group);
 
-    libbalsa_conf_sync();
+    libbalsa_conf_queue_sync();
 }
 
 static void
@@ -436,7 +436,7 @@ file_delete_cb(GtkAction * action, gpointer user_data)
     if (address_book->config_prefix) {
         libbalsa_conf_remove_group(address_book->config_prefix);
         libbalsa_conf_private_remove_group(address_book->config_prefix);
-        libbalsa_conf_sync();
+        libbalsa_conf_queue_sync();
     }
 
     merge_id = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(address_book),
diff --git a/src/save-restore.c b/src/save-restore.c
index a868985..d283b82 100644
--- a/src/save-restore.c
+++ b/src/save-restore.c
@@ -260,7 +260,7 @@ config_address_book_save(LibBalsaAddressBook * ab)
 
     g_free(group);
 
-    libbalsa_conf_sync();
+    libbalsa_conf_queue_sync();
 }
 
 void
@@ -269,7 +269,7 @@ config_address_book_delete(LibBalsaAddressBook * ab)
     if (ab->config_prefix) {
        libbalsa_conf_remove_group(ab->config_prefix);
        libbalsa_conf_private_remove_group(ab->config_prefix);
-       libbalsa_conf_sync();
+       libbalsa_conf_queue_sync();
     }
 }
 
@@ -293,7 +293,7 @@ gint config_mailbox_add(LibBalsaMailbox * mailbox, const char *key_arg)
     libbalsa_conf_pop_group();
     g_free(tmp);
 
-    libbalsa_conf_sync();
+    libbalsa_conf_queue_sync();
     return TRUE;
 }                              /* config_mailbox_add */
 
@@ -316,7 +316,7 @@ gint config_folder_add(BalsaMailboxNode * mbnode, const char *key_arg)
     libbalsa_conf_pop_group();
     g_free(tmp);
 
-    libbalsa_conf_sync();
+    libbalsa_conf_queue_sync();
     return TRUE;
 }                              /* config_mailbox_add */
 
@@ -328,7 +328,7 @@ gint config_mailbox_delete(const LibBalsaMailbox * mailbox)
     tmp = mailbox_section_path(mailbox);
     res = libbalsa_conf_has_group(tmp);
     libbalsa_conf_remove_group(tmp);
-    libbalsa_conf_sync();
+    libbalsa_conf_queue_sync();
     g_free(tmp);
     return res;
 }                              /* config_mailbox_delete */
@@ -341,7 +341,7 @@ config_folder_delete(const BalsaMailboxNode * mbnode)
     tmp = folder_section_path(mbnode);
     res = libbalsa_conf_has_group(tmp);
     libbalsa_conf_remove_group(tmp);
-    libbalsa_conf_sync();
+    libbalsa_conf_queue_sync();
     g_free(tmp);
     return res;
 }                              /* config_folder_delete */
@@ -360,7 +360,7 @@ gint config_mailbox_update(LibBalsaMailbox * mailbox)
     libbalsa_mailbox_save_config(mailbox, key);
     g_free(key);
     libbalsa_conf_pop_group();
-    libbalsa_conf_sync();
+    libbalsa_conf_queue_sync();
     return res;
 }                              /* config_mailbox_update */
 
@@ -378,7 +378,7 @@ gint config_folder_update(BalsaMailboxNode * mbnode)
     balsa_mailbox_node_save_config(mbnode, key);
     g_free(key);
     libbalsa_conf_pop_group();
-    libbalsa_conf_sync();
+    libbalsa_conf_queue_sync();
     return res;
 }                              /* config_folder_update */
 
@@ -1979,7 +1979,7 @@ config_filters_save(void)
        libbalsa_filter_save_config(fil);
        libbalsa_conf_pop_group();
     }
-    libbalsa_conf_sync();
+    libbalsa_conf_queue_sync();
     /* This loop takes care of cleaning up old filter sections */
     while (TRUE) {
        i=snprintf(tmp,tmp_len,"%d",nb++);
@@ -1990,7 +1990,7 @@ config_filters_save(void)
        }
        else break;
     }
-    libbalsa_conf_sync();
+    libbalsa_conf_queue_sync();
     g_free(buffer);
 }
 
@@ -2021,7 +2021,7 @@ config_mailbox_filters_save(LibBalsaMailbox * mbox)
     }
     libbalsa_mailbox_filters_save_config(mbox);
     libbalsa_conf_pop_group();
-    libbalsa_conf_sync();
+    libbalsa_conf_queue_sync();
 }
 
 static void


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