[tracker] libtracker-miner: Pause crawler when miner is paused



commit c7b91724f8e7aeef104b734d522738520a3d7f55
Author: Martyn Russell <martyn lanedo com>
Date:   Tue Sep 8 14:16:22 2009 +0100

    libtracker-miner: Pause crawler when miner is paused

 src/libtracker-miner/tracker-crawler.c  |   51 +++++++++++++++++++++++++++----
 src/libtracker-miner/tracker-crawler.h  |    2 +
 src/libtracker-miner/tracker-miner-fs.c |   37 ++++++++++++++--------
 3 files changed, 71 insertions(+), 19 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-crawler.c b/src/libtracker-miner/tracker-crawler.c
index f69c366..4ea5b64 100644
--- a/src/libtracker-miner/tracker-crawler.c
+++ b/src/libtracker-miner/tracker-crawler.c
@@ -64,6 +64,7 @@ struct TrackerCrawlerPrivate {
 	/* Status */
 	gboolean	is_running;
 	gboolean	is_finished;
+	gboolean        is_paused;
 	gboolean        was_started;
 };
 
@@ -279,13 +280,12 @@ process_func (gpointer data)
 	crawler = TRACKER_CRAWLER (data);
 	priv = crawler->private;
 
-#ifdef FIX
-	/* If manually paused, we hold off until unpaused */
-	if (tracker_status_get_is_paused_manually () ||
-	    tracker_status_get_is_paused_for_io ()) {
-		return TRUE;
+	if (priv->is_paused) {
+		/* Stop the idle func for now until we are unpaused */
+		priv->idle_id = 0;
+
+		return FALSE;
 	}
-#endif
 
 	/* Throttle the crawler, with testing, throttling every item
 	 * took the time to crawl 130k files from 7 seconds up to 68
@@ -691,3 +691,42 @@ tracker_crawler_stop (TrackerCrawler *crawler)
 	 * is only freed in finalize.
 	 */
 }
+
+void
+tracker_crawler_pause (TrackerCrawler *crawler)
+{
+	g_return_if_fail (TRACKER_IS_CRAWLER (crawler));
+	
+	crawler->private->is_paused = TRUE;
+
+	if (crawler->private->is_running) {
+		g_timer_stop (crawler->private->timer);
+		
+		if (crawler->private->idle_id != 0) {
+			g_source_remove (crawler->private->idle_id);
+			crawler->private->idle_id = 0;
+		}
+	}
+
+	g_message ("Crawler is paused, %s", 
+		   crawler->private->is_running ? "currently running" : "not running");
+}
+
+void
+tracker_crawler_resume (TrackerCrawler *crawler)
+{
+	g_return_if_fail (TRACKER_IS_CRAWLER (crawler));
+
+	crawler->private->is_paused = FALSE;
+
+	if (crawler->private->is_running) {
+		g_timer_continue (crawler->private->timer);
+
+		if (crawler->private->idle_id == 0) {
+			crawler->private->idle_id = g_idle_add (process_func, crawler);
+		}
+	}
+
+	g_message ("Crawler is resuming, %s", 
+		   crawler->private->is_running ? "currently running" : "not running");
+}
diff --git a/src/libtracker-miner/tracker-crawler.h b/src/libtracker-miner/tracker-crawler.h
index 74f6838..6801d7a 100644
--- a/src/libtracker-miner/tracker-crawler.h
+++ b/src/libtracker-miner/tracker-crawler.h
@@ -62,6 +62,8 @@ gboolean        tracker_crawler_start    (TrackerCrawler *crawler,
 					  GFile          *file,
 					  gboolean        recurse);
 void            tracker_crawler_stop     (TrackerCrawler *crawler);
+void            tracker_crawler_pause    (TrackerCrawler *crawler);
+void            tracker_crawler_resume   (TrackerCrawler *crawler);
 
 G_END_DECLS
 
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index dd3d678..b5d9238 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -67,7 +67,7 @@ struct TrackerMinerFSPrivate {
 	guint           been_started : 1;
 	guint           been_crawled : 1;
 	guint           shown_totals : 1;
-	guint           paused : 1;
+	guint           is_paused : 1;
 
 	/* Statistics */
 	guint		total_directories_found;
@@ -349,29 +349,40 @@ miner_stopped (TrackerMiner *miner)
 static void
 miner_paused (TrackerMiner *miner)
 {
-	TrackerMinerFSPrivate *priv;
+	TrackerMinerFS *fs;
 
-	priv = TRACKER_MINER_FS (miner)->private;
+	fs = TRACKER_MINER_FS (miner);
 
-	priv->paused = TRUE;
+	fs->private->is_paused = TRUE;
 
-	/* FIXME: also pause crawler, if running */
+	tracker_crawler_pause (fs->private->crawler);
 
-	if (priv->item_queues_handler_id) {
-		g_source_remove (priv->item_queues_handler_id);
-		priv->item_queues_handler_id = 0;
+	if (fs->private->item_queues_handler_id) {
+		g_source_remove (fs->private->item_queues_handler_id);
+		fs->private->item_queues_handler_id = 0;
 	}
 }
 
 static void
 miner_resumed (TrackerMiner *miner)
 {
-	TrackerMinerFSPrivate *priv;
+	TrackerMinerFS *fs;
+
+	fs = TRACKER_MINER_FS (miner);
+
+	fs->private->is_paused = FALSE;
 
-	priv = TRACKER_MINER_FS (miner)->private;
+	tracker_crawler_resume (fs->private->crawler);
 
-	priv->paused = FALSE;
-	item_queue_handlers_set_up (TRACKER_MINER_FS (miner));
+	/* Only set up queue handler if we have items waiting to be
+	 * processed.
+	 */
+	if (g_queue_get_length (fs->private->items_deleted) > 0 ||
+	    g_queue_get_length (fs->private->items_created) > 0 ||
+	    g_queue_get_length (fs->private->items_updated) > 0 ||
+	    g_queue_get_length (fs->private->items_moved) > 0) {
+		item_queue_handlers_set_up (fs);
+	}
 }
 
 static DirectoryData *
@@ -878,7 +889,7 @@ item_queue_handlers_set_up (TrackerMinerFS *fs)
 		return;
 	}
 
-	if (fs->private->paused) {
+	if (fs->private->is_paused) {
 		return;
 	}
 



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