[tracker/writeback-refactor-rebase: 27/65] libtracker-miner: Use the task pool for ongoing writeback operations



commit cf589d91325efbdb25afd785f665fd807b3ec837
Author: Carlos Garnacho <carlos lanedo com>
Date:   Tue Jul 19 12:45:41 2011 +0200

    libtracker-miner: Use the task pool for ongoing writeback operations

 src/libtracker-miner/tracker-marshal.list |    2 +-
 src/libtracker-miner/tracker-miner-fs.c   |   53 +++++++++++++++++++++++++---
 src/libtracker-miner/tracker-miner-fs.h   |    2 +-
 3 files changed, 49 insertions(+), 8 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-marshal.list b/src/libtracker-miner/tracker-marshal.list
index 2218262..4a323a0 100644
--- a/src/libtracker-miner/tracker-marshal.list
+++ b/src/libtracker-miner/tracker-marshal.list
@@ -11,4 +11,4 @@ BOOL:OBJECT,OBJECT,OBJECT
 BOOL:OBJECT,OBJECT
 BOOL:OBJECT,POINTER
 BOOL:OBJECT
-VOID:OBJECT,BOXED,BOXED
+BOOL:OBJECT,BOXED,BOXED
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index 23731ee..604a8f7 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -691,8 +691,8 @@ tracker_miner_fs_class_init (TrackerMinerFSClass *klass)
 		              G_STRUCT_OFFSET (TrackerMinerFSClass, writeback_file),
 		              NULL,
 		              NULL,
-		              tracker_marshal_VOID__OBJECT_BOXED_BOXED,
-		              G_TYPE_NONE,
+		              tracker_marshal_BOOLEAN__OBJECT_BOXED_BOXED,
+		              G_TYPE_BOOLEAN,
 		              3,
 		              G_TYPE_FILE,
 		              G_TYPE_STRV,
@@ -2543,19 +2543,23 @@ item_queue_get_next_file (TrackerMinerFS  *fs,
 	wdata = tracker_priority_queue_pop (fs->priv->items_writeback,
 					    &priority);
 	if (wdata) {
+		gboolean processing;
+
 		*file = g_object_ref (wdata->file);
 		*source_file = NULL;
+		*priority_out = priority;
 
 		trace_eq_pop_head ("WRITEBACK", wdata->file);
 
 		g_signal_emit (fs, signals[WRITEBACK_FILE], 0,
 		               wdata->file,
 		               wdata->rdf_types,
-		               wdata->results);
+		               wdata->results,
+			       &processing);
 
 		item_writeback_data_free (wdata);
 
-		return QUEUE_WRITEBACK;
+		return (processing) ? QUEUE_WRITEBACK : QUEUE_NONE;
 	}
 
 	/* Deleted items second */
@@ -3037,9 +3041,16 @@ item_queue_handlers_cb (gpointer user_data)
 	case QUEUE_IGNORE_NEXT_UPDATE:
 		keep_processing = item_ignore_next_update (fs, file, source_file);
 		break;
-	case QUEUE_WRITEBACK:
-		/* All work is already done at an earlier stage */
+	case QUEUE_WRITEBACK: {
+		TrackerTask *task;
+
+		/* The signal was emitted at an earlier stage,
+		 * so here we just add the task to the task pool
+		 */
+		task = tracker_task_new (file, NULL, NULL);
+		tracker_task_pool_add (fs->priv->task_pool, task);
 		keep_processing = TRUE;
+	}
 		break;
 	default:
 		g_assert_not_reached ();
@@ -4456,6 +4467,11 @@ task_pool_cancel_foreach (gpointer data,
 	UpdateProcessingTaskContext *ctxt;
 
 	ctxt = tracker_task_get_data (task);
+
+	if (!ctxt) {
+		return;
+	}
+
 	task_file = tracker_task_get_file (task);
 
 	if (ctxt &&
@@ -4751,6 +4767,31 @@ tracker_miner_fs_writeback_notify (TrackerMinerFS *fs,
                                    GFile          *file,
                                    const GError   *error)
 {
+	TrackerTask *task;
+
+	g_return_if_fail (TRACKER_IS_MINER_FS (fs));
+	g_return_if_fail (G_IS_FILE (file));
+
+	fs->priv->total_files_notified++;
+
+	task = tracker_task_pool_find (fs->priv->task_pool, file);
+
+	if (!task) {
+		gchar *uri;
+
+		uri = g_file_get_uri (file);
+		g_critical ("%s has notified that file '%s' has been written back, "
+		            "but that file was not in the task pool. "
+		            "This is an implementation error, please ensure that "
+		            "tracker_miner_fs_writeback_notify() is called on the same "
+		            "GFile that is passed in ::writeback-file, and that this"
+		            "signal didn't return FALSE for it",
+		            G_OBJECT_TYPE_NAME (fs), uri);
+		g_free (uri);
+	} else {
+		tracker_task_pool_remove (fs->priv->task_pool, task);
+		tracker_task_unref (task);
+	}
 }
 
 /**
diff --git a/src/libtracker-miner/tracker-miner-fs.h b/src/libtracker-miner/tracker-miner-fs.h
index 0b7efd2..bf74efc 100644
--- a/src/libtracker-miner/tracker-miner-fs.h
+++ b/src/libtracker-miner/tracker-miner-fs.h
@@ -105,7 +105,7 @@ typedef struct {
 	                                       GFile                *file,
 	                                       TrackerSparqlBuilder *builder,
 	                                       GCancellable         *cancellable);
-	void     (* writeback_file)           (TrackerMinerFS       *fs,
+	gboolean (* writeback_file)           (TrackerMinerFS       *fs,
 	                                       GFile                *file,
 	                                       GStrv                 rdf_types,
 	                                       GPtrArray            *results);



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