[tracker/collation-gconf-locale: 2/28] libtracker-common: thread-safe locale string management



commit cc77963325678852c641349e41ea50912e8bcd8b
Author: Aleksander Morgado <aleksander lanedo com>
Date:   Wed Sep 1 18:54:48 2010 +0200

    libtracker-common: thread-safe locale string management

 src/libtracker-common/tracker-locale.c |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)
---
diff --git a/src/libtracker-common/tracker-locale.c b/src/libtracker-common/tracker-locale.c
index c17aa3d..153dd88 100644
--- a/src/libtracker-common/tracker-locale.c
+++ b/src/libtracker-common/tracker-locale.c
@@ -130,10 +130,15 @@ tracker_locale_gconf_notify_cb (GConfClient *client,
 		return;
 	}
 
+	/* Protect the locale change with the lock */
+	LOCK;
+
 	/* Clean the previous value */
 	g_free (current_locales[i]);
 	/* And set the new one that got just notified */
 	current_locales[i] = g_strdup (gconf_value_get_string (value));
+
+	UNLOCK;
 }
 
 #endif /* HAVE_MAEMO */
@@ -231,12 +236,19 @@ tracker_locale_get (TrackerLocaleID id)
 {
 	gchar *locale;
 
+	/* Lock even before checking if initialized, so that initialization is
+	 * not done twice */
+	LOCK;
+
 	/* Initialize if not already done */
-	if (!initialized) {
+	if (!initialized)
 		tracker_locale_init ();
-	}
 
+	/* Always return a duplicated string, as the locale may change at any
+	 * moment */
 	locale = g_strdup (current_locales[i]);
 
+	UNLOCK;
+
 	return locale;
 }



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