[tracker/collation-gconf-locale: 15/24] tracker-store: Perform locale change processing in an idle to avoid deadlock



commit 7d3a81e14ed34f6234c931188fc4a502aff90fc7
Author: Aleksander Morgado <aleksander lanedo com>
Date:   Thu Oct 28 18:19:06 2010 +0200

    tracker-store: Perform locale change processing in an idle to avoid deadlock

 src/libtracker-data/tracker-data-manager.c |   26 ++++++++++++++++--------
 src/tracker-store/tracker-main.c           |   29 +++++++++++++++++++++++++--
 2 files changed, 43 insertions(+), 12 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index c64fcbe..4f291fe 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -3080,21 +3080,29 @@ tracker_data_manager_reload (TrackerBusyCallback busy_callback,
 	guint select_cache_size;
 	guint update_cache_size;
 	gboolean is_first;
+	gboolean status;
 
+	g_message ("Reloading data manager...");
 	/* Shutdown data manager... */
 	flags = tracker_db_manager_get_flags (&select_cache_size, &update_cache_size);
 	tracker_data_manager_shutdown ();
 
+	g_message ("  Data manager shut down, now initializing again...");
+
 	/* And initialize it again, this actually triggers index recreation. */
-	return tracker_data_manager_init (flags,
-	                                  NULL,
-	                                  &is_first,
-	                                  TRUE,
-	                                  select_cache_size,
-	                                  update_cache_size,
-	                                  busy_callback,
-	                                  busy_user_data,
-	                                  "Reloading data manager");
+	status = tracker_data_manager_init (flags,
+	                                    NULL,
+	                                    &is_first,
+	                                    TRUE,
+	                                    select_cache_size,
+	                                    update_cache_size,
+	                                    busy_callback,
+	                                    busy_user_data,
+	                                    "Reloading data manager");
+
+	g_message ("  %s reloading data manager",
+	           status ? "Succeeded" : "Failed");
+	return status;
 }
 
 gboolean
diff --git a/src/tracker-store/tracker-main.c b/src/tracker-store/tracker-main.c
index 3972a6b..fbbf6fb 100644
--- a/src/tracker-store/tracker-main.c
+++ b/src/tracker-store/tracker-main.c
@@ -85,6 +85,7 @@ typedef struct {
 /* Private */
 static GStaticPrivate private_key = G_STATIC_PRIVATE_INIT;
 static gpointer locale_notification_id;
+static gboolean locale_change_notified;
 
 /* Private command line parameters */
 static gboolean version;
@@ -263,9 +264,8 @@ shutdown_directories (void)
 	}
 }
 
-static void
-tracker_locale_notify_cb (TrackerLocaleID id,
-                          gpointer        user_data)
+static gboolean
+tracker_locale_change_process_cb (gpointer data)
 {
 	TrackerStatus *notifier;
 	TrackerBusyCallback busy_callback;
@@ -281,6 +281,29 @@ tracker_locale_notify_cb (TrackerLocaleID id,
 	tracker_data_manager_reload (NULL, NULL);
 
 	tracker_store_set_active (TRUE);
+
+	locale_change_notified = FALSE;
+
+	return FALSE;
+}
+
+static void
+tracker_locale_notify_cb (TrackerLocaleID id,
+                          gpointer        user_data)
+{
+	if (locale_change_notified) {
+		g_message ("Locale change was already notified, not doing it again");
+	} else {
+		locale_change_notified = TRUE;
+		/* Set an idle callback to process the locale change.
+		 * NOTE: We cannot process it right here because we will be
+		 * closing and opening new connections to the DB while doing it,
+		 * and the DB connections are also part of the subscriber list
+		 * for locale changes, so we may end up waiting to acquire an
+		 * already locked mutex.
+		 */
+		g_idle_add (tracker_locale_change_process_cb, NULL);
+	}
 }
 
 static void



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