[tracker/async-queries-wip: 20/23] WIP



commit db18f6a8b05898d586efa9ecfa9cdffbb0aea5b1
Author: Jürg Billeter <j bitron ch>
Date:   Wed Apr 14 18:42:01 2010 +0200

    WIP

 src/libtracker-db/tracker-db-manager.c |   36 ++++++++++++++++++++++++++++++++
 src/libtracker-db/tracker-db-manager.h |    3 ++
 src/tracker-store/tracker-store.c      |    8 ++----
 3 files changed, 42 insertions(+), 5 deletions(-)
---
diff --git a/src/libtracker-db/tracker-db-manager.c b/src/libtracker-db/tracker-db-manager.c
index 4dc776f..2180b0e 100644
--- a/src/libtracker-db/tracker-db-manager.c
+++ b/src/libtracker-db/tracker-db-manager.c
@@ -1522,3 +1522,39 @@ tracker_db_interface_pool_execute_query_async (TrackerDBInterfacePool *pool,
 		pool_job_destroy (job);
 	}
 }
+
+#define PENDING_BYTE 0x40000000
+#define SHARED_FIRST (PENDING_BYTE+2)
+#define SHARED_SIZE 510
+
+gboolean
+tracker_db_manager_pending_lock (void)
+{
+	static int fd1 = -1;
+	static int fd2 = -1;
+
+	if (G_UNLIKELY (fd1 == -1)) {
+		fd1 = open ("/home/juerg/.cache/tracker/meta.db", O_RDWR);
+		fd2 = open ("/home/juerg/.cache/tracker/fulltext.db", O_RDWR);
+	}
+
+	struct flock lock;
+	lock.l_len = SHARED_SIZE;
+	lock.l_whence = SEEK_SET;
+	lock.l_type = F_WRLCK;
+	lock.l_start = SHARED_FIRST;
+	if (fcntl (fd1, F_SETLK, &lock) == -1) {
+		/* wouldn't be able to get exclusive lock, must already be locked */
+		return TRUE;
+	} else {
+		lock.l_type = F_WRLCK;
+		if (fcntl (fd2, F_SETLK, &lock) == -1) {
+			/* wouldn't be able to get exclusive lock, must already be locked */
+			return TRUE;
+		}
+		lock.l_type = F_UNLCK;
+		fcntl (fd1, F_SETLK, &lock);
+		lock.l_type = F_UNLCK;
+		fcntl (fd2, F_SETLK, &lock);
+	}
+}
diff --git a/src/libtracker-db/tracker-db-manager.h b/src/libtracker-db/tracker-db-manager.h
index 7e7b865..b3e44bf 100644
--- a/src/libtracker-db/tracker-db-manager.h
+++ b/src/libtracker-db/tracker-db-manager.h
@@ -104,6 +104,9 @@ void                 tracker_db_interface_pool_execute_query_async  (TrackerDBIn
                                                                      GAsyncReadyCallback     callback,
                                                                      gpointer                user_data);
 
+gboolean
+tracker_db_manager_pending_lock (void);
+
 G_END_DECLS
 
 #endif /* __LIBTRACKER_DB_MANAGER_H__ */
diff --git a/src/tracker-store/tracker-store.c b/src/tracker-store/tracker-store.c
index 5537018..9faa238 100644
--- a/src/tracker-store/tracker-store.c
+++ b/src/tracker-store/tracker-store.c
@@ -315,8 +315,6 @@ queue_idle_handler (gpointer user_data)
 	if (task->type == TRACKER_STORE_TASK_TYPE_QUERY) {
 		TrackerSparqlQuery *sparql_query;
 
-		end_batch (private);
-
 		private->n_queries_running++;
 
 		/* pop task now, otherwise further queries won't be scheduled */
@@ -343,7 +341,7 @@ queue_idle_handler (gpointer user_data)
 		if (task->data.update.batch) {
 			if (!error) {
 				private->batch_count++;
-				if (private->batch_count >= TRACKER_STORE_TRANSACTION_MAX) {
+				if (tracker_db_manager_pending_lock ()) {
 					end_batch (private);
 				}
 			}
@@ -374,7 +372,7 @@ queue_idle_handler (gpointer user_data)
 		if (task->data.update.batch) {
 			if (!error) {
 				private->batch_count++;
-				if (private->batch_count >= TRACKER_STORE_TRANSACTION_MAX) {
+				if (tracker_db_manager_pending_lock ()) {
 					end_batch (private);
 				}
 			}
@@ -434,7 +432,7 @@ queue_idle_handler (gpointer user_data)
 		if (process_turtle_file_part (turtle_reader, &error)) {
 			/* import still in progress */
 			private->batch_count++;
-			if (private->batch_count >= TRACKER_STORE_TRANSACTION_MAX) {
+			if (tracker_db_manager_pending_lock ()) {
 				end_batch (private);
 			}
 



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