[tracker/collation-gconf-locale: 2/3] libtracker-common: thread-safe locale string management
- From: Aleksander Morgado <aleksm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/collation-gconf-locale: 2/3] libtracker-common: thread-safe locale string management
- Date: Wed, 1 Sep 2010 18:08:49 +0000 (UTC)
commit ac065e7701b019c88d94d89de8ff9f909dd10fb8
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]