evolution-data-server r9141 - trunk/camel



Author: sragavan
Date: Sun Jul 20 13:33:28 2008
New Revision: 9141
URL: http://svn.gnome.org/viewvc/evolution-data-server?rev=9141&view=rev

Log:
Move freeing stuff to a proper thread rather than the main thread, which hangs the UI at times.


Modified:
   trunk/camel/camel-db.c
   trunk/camel/camel-db.h
   trunk/camel/camel-folder-summary.c

Modified: trunk/camel/camel-db.c
==============================================================================
--- trunk/camel/camel-db.c	(original)
+++ trunk/camel/camel-db.c	Sun Jul 20 13:33:28 2008
@@ -37,9 +37,6 @@
 
 #define d(x) 
 
-#define CAMEL_DB_SLEEP_INTERVAL 1*10*10
-#define CAMEL_DB_RELEASE_SQLITE_MEMORY if(!g_getenv("CAMEL_SQLITE_PRESERVE_CACHE")) sqlite3_release_memory(CAMEL_DB_FREE_CACHE_SIZE);
-#define CAMEL_DB_USE_SHARED_CACHE if(!g_getenv("CAMEL_SQLITE_SHARED_CACHE_OFF")) sqlite3_enable_shared_cache(TRUE);
 
 static int 
 cdb_sql_exec (sqlite3 *db, const char* stmt, CamelException *ex) 
@@ -74,8 +71,6 @@
 
 	CAMEL_DB_USE_SHARED_CACHE;
 	
-	sqlite3_enable_shared_cache(TRUE);
-
 	ret = sqlite3_open(path, &db);
 	if (ret) {
 

Modified: trunk/camel/camel-db.h
==============================================================================
--- trunk/camel/camel-db.h	(original)
+++ trunk/camel/camel-db.h	Sun Jul 20 13:33:28 2008
@@ -14,6 +14,10 @@
 };
 
 #define CAMEL_DB_FREE_CACHE_SIZE 2 * 1024 * 1024
+#define CAMEL_DB_SLEEP_INTERVAL 1*10*10
+#define CAMEL_DB_RELEASE_SQLITE_MEMORY if(!g_getenv("CAMEL_SQLITE_PRESERVE_CACHE")) sqlite3_release_memory(CAMEL_DB_FREE_CACHE_SIZE);
+#define CAMEL_DB_USE_SHARED_CACHE if(!g_getenv("CAMEL_SQLITE_SHARED_CACHE_OFF")) sqlite3_enable_shared_cache(TRUE);
+
 
 /* The extensive DB format, supporting basic searching and sorting
   uid, - Message UID

Modified: trunk/camel/camel-folder-summary.c
==============================================================================
--- trunk/camel/camel-folder-summary.c	(original)
+++ trunk/camel/camel-folder-summary.c	Sun Jul 20 13:33:28 2008
@@ -52,6 +52,7 @@
 #include "camel-mime-message.h"
 #include "camel-multipart.h"
 #include "camel-private.h"
+#include "camel-session.h"
 #include "camel-stream-filter.h"
 #include "camel-stream-mem.h"
 #include "camel-stream-null.h"
@@ -699,8 +700,8 @@
 		CAMEL_SUMMARY_UNLOCK(info->summary, ref_lock);
 		/* Hackit so that hashtable isn;t corrupted. */
 		/* FIXME: These uid strings are not yet freed. We should get this done soon. */
-		//camel_pstring_free (info->uid);
-		//info->uid = NULL;
+		camel_pstring_free (info->uid);
+		info->uid = NULL;
 		/* Noone seems to need it. Why not free it then. */
 		camel_message_info_free (info);
 		return TRUE;
@@ -709,16 +710,24 @@
 	return FALSE;
 }
 
-static gboolean      
-remove_cache (CamelFolderSummary *s)
+
+struct _folder_summary_free_msg {
+	CamelSessionThreadMsg msg;
+	CamelFolderSummary *summary;
+};
+
+static void      
+remove_cache (CamelSession *session, CamelSessionThreadMsg *msg)
 {
-	/* Attempt to release 2MB*/
-        sqlite3_release_memory(CAMEL_DB_FREE_CACHE_SIZE); 
+	struct _folder_summary_free_msg *m = (struct _folder_summary_free_msg *)msg;		
+	CamelFolderSummary *s = m->summary;
+
+	CAMEL_DB_RELEASE_SQLITE_MEMORY;
 	
 	if (time(NULL) - s->cache_load_time < SUMMARY_CACHE_DROP)
-		return TRUE;
+		return;
 	
-	printf("removing cache for  %s %d\n", s->folder->full_name, g_hash_table_size (s->loaded_infos));
+	printf("removing cache for  %s %d %p\n", s->folder->full_name, g_hash_table_size (s->loaded_infos), s->loaded_infos);
 	#warning "hack. fix it"
 	CAMEL_SUMMARY_LOCK (s, summary_lock);
 	g_hash_table_foreach_remove  (s->loaded_infos, (GHRFunc) remove_item, s);
@@ -727,6 +736,36 @@
 
 	s->cache_load_time = time(NULL);
 	
+	return;
+}
+
+
+
+static void remove_cache_end (CamelSession *session, CamelSessionThreadMsg *msg)
+{
+		struct _folder_summary_free_msg *m = (struct _folder_summary_free_msg *)msg;
+		camel_object_unref (m->summary);
+}
+
+static CamelSessionThreadOps remove_timeout_ops = {
+	remove_cache,
+	remove_cache_end,
+};
+
+static gboolean
+cfs_try_release_memory (CamelFolderSummary *s)
+{
+	struct _folder_summary_free_msg *m;
+	CamelSession *session = ((CamelService *)((CamelFolder *)s->folder)->parent_store)->session;
+
+	if (time(NULL) - s->cache_load_time < SUMMARY_CACHE_DROP)
+		return TRUE;
+
+	m = camel_session_thread_msg_new(session, &remove_timeout_ops, sizeof(*m));
+	camel_object_ref (s);
+	m->summary = s;
+	camel_session_thread_queue(session, &m->msg, 0);
+
 	return TRUE;
 }
 
@@ -792,8 +831,9 @@
 	ret = camel_db_read_message_info_records (cdb, folder_name, (gpointer) &data, camel_read_mir_callback, ex);
 #endif	
 	s->cache_load_time = time (NULL);
-	#warning "LRU please and not timeouts"
-	s->timeout_handle = g_timeout_add_seconds (SUMMARY_CACHE_DROP, (GSourceFunc) remove_cache, s);
+
+        #warning "LRU please and not timeouts"
+	s->timeout_handle = g_timeout_add_seconds (SUMMARY_CACHE_DROP, (GSourceFunc) cfs_try_release_memory, s);
 
 	return ret == 0 ? 0 : -1;
 }



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