Author: Arjan van de Ven <arjan@linux.intel.com>

Evolution has 2 event queues that are polled 10 times per second
for activity; these queues are empty most of the time.

This patch changes the code so that the timer to poll these queues
only runs when there are actually events going on; if there are no 
events, the timer will stop.

 mail-mt.c |   34 +++++++++++++++++++++++++++-------
 1 file changed, 27 insertions(+), 7 deletions(-)


--- evolution-2.10.1/mail/mail-mt.c.org	2007-04-16 15:25:56.000000000 -0700
+++ evolution-2.10.1/mail/mail-mt.c	2007-04-16 16:53:54.000000000 -0700
@@ -435,6 +435,8 @@ static gboolean
 periodic_processing (void)
 {
 	mail_msg_t *msg;
+	
+	periodic_source_id = 0;
 
 	g_assert (main_loop_queue != NULL);
 	g_assert (msg_reply_queue != NULL);
@@ -466,7 +468,7 @@ periodic_processing (void)
 		mail_msg_free (msg);
 	}
 
-	return TRUE;
+	return FALSE;
 }
 
 static void
@@ -495,6 +497,12 @@ mail_msg_proxy (mail_msg_t *msg)
 	}
 
 	g_async_queue_push (msg_reply_queue, msg);
+	if (periodic_source_id == 0)
+		periodic_source_id = g_timeout_add_full (
+		G_PRIORITY_DEFAULT,
+		1000 / PERIODIC_RATE_HZ,
+		(GSourceFunc) periodic_processing, NULL,
+		NULL);
 }
 
 void
@@ -504,11 +512,15 @@ mail_msg_cleanup (void)
 
 	mail_msg_wait_all();
 
-	/* stop periodic processing */
-	source = g_main_context_find_source_by_id (
-		g_main_context_default (), periodic_source_id);
-	g_assert (source != NULL);
-	g_source_destroy (source);
+	if (periodic_source_id) {
+		/* stop periodic processing */
+		source = g_main_context_find_source_by_id (
+			g_main_context_default (), periodic_source_id);
+		g_assert (source != NULL);
+		g_source_destroy (source);
+		periodic_source_id = 0;
+	}
+	periodic_cleanup();
 }
 
 void
@@ -522,7 +534,7 @@ mail_msg_init (void)
 		G_PRIORITY_DEFAULT,
 		1000 / PERIODIC_RATE_HZ,
 		(GSourceFunc) periodic_processing, NULL,
-		(GDestroyNotify) periodic_cleanup);
+		NULL);
 
 	mail_msg_active_table = g_hash_table_new (NULL, NULL);
 	main_thread = g_thread_self ();
@@ -562,6 +574,14 @@ mail_msg_main_loop_push (mail_msg_t *msg
 {
 	g_async_queue_push_sorted (main_loop_queue, msg,
 		(GCompareDataFunc) mail_msg_compare, NULL);
+		
+	if (periodic_source_id == 0)
+		periodic_source_id = g_timeout_add_full (
+		G_PRIORITY_DEFAULT,
+		1000 / PERIODIC_RATE_HZ,
+		(GSourceFunc) periodic_processing, NULL,
+		NULL);
+
 }
 
 void
