From f1494c156dcbbe125807ef2a1b5ab0ca4b2acc66 Mon Sep 17 00:00:00 2001 From: Ryan Lortie Date: Fri, 9 Sep 2011 19:48:14 -0400 Subject: [PATCH] Clean up l10n threading stuff Remove the explicit thread initialisation functions for g_get_charset(), g_get_filename_charsets() and g_get_language_names(). Add a lock around one remaining case of access to libcharset (the other 2 cases already have the lock). Do a proper g_once_init_enter() style initialisation for the GLib gettext functions. https://bugzilla.gnome.org/show_bug.cgi?id=658683 --- glib/gconvert.c | 10 ---------- glib/gthread.c | 4 ---- glib/gthreadprivate.h | 2 -- glib/gutf8.c | 2 ++ glib/gutils.c | 19 ++++++------------- 5 files changed, 8 insertions(+), 29 deletions(-) diff --git a/glib/gconvert.c b/glib/gconvert.c index c5845ca..86a2c0e 100644 --- a/glib/gconvert.c +++ b/glib/gconvert.c @@ -1425,16 +1425,6 @@ get_filename_charset (const gchar **filename_charset) return is_utf8; } -/* This is called from g_thread_init(). It's used to - * initialize some static data in a threadsafe way. - */ -void -_g_convert_thread_init (void) -{ - const gchar **dummy; - (void) g_get_filename_charsets (&dummy); -} - /** * g_filename_to_utf8: * @opsysstring: a string in the encoding for filenames diff --git a/glib/gthread.c b/glib/gthread.c index 26ff386..cc8e717 100644 --- a/glib/gthread.c +++ b/glib/gthread.c @@ -957,10 +957,6 @@ g_thread_init_glib (void) /* accomplish log system initialization to enable messaging */ _g_messages_thread_init_nomessage (); - - /* we may run full-fledged initializers from here */ - _g_convert_thread_init (); - _g_utils_thread_init (); } /* The following sections implement: GOnce, GStaticMutex, GStaticRecMutex, diff --git a/glib/gthreadprivate.h b/glib/gthreadprivate.h index d0c8b33..3887519 100644 --- a/glib/gthreadprivate.h +++ b/glib/gthreadprivate.h @@ -53,8 +53,6 @@ G_GNUC_INTERNAL void _g_slice_thread_init_nomessage (void); G_GNUC_INTERNAL void _g_messages_thread_init_nomessage (void); /* full fledged initializers */ -G_GNUC_INTERNAL void _g_convert_thread_init (void); -G_GNUC_INTERNAL void _g_utils_thread_init (void); G_GNUC_INTERNAL void _g_thread_impl_init (void); G_END_DECLS diff --git a/glib/gutf8.c b/glib/gutf8.c index 7344e39..f6d721b 100644 --- a/glib/gutf8.c +++ b/glib/gutf8.c @@ -597,7 +597,9 @@ g_get_charset (const char **charset) g_static_private_set (&cache_private, cache, charset_cache_free); } + G_LOCK (aliases); raw = _g_locale_charset_raw (); + G_UNLOCK (aliases); if (!(cache->raw && strcmp (cache->raw, raw) == 0)) { diff --git a/glib/gutils.c b/glib/gutils.c index 679bab7..162c2cf 100644 --- a/glib/gutils.c +++ b/glib/gutils.c @@ -3648,15 +3648,6 @@ g_get_codeset (void) return g_strdup (charset); } -/* This is called from g_thread_init(). It's used to - * initialize some static data in a threadsafe way. - */ -void -_g_utils_thread_init (void) -{ - g_get_language_names (); -} - #ifdef G_OS_WIN32 /** @@ -3707,11 +3698,13 @@ _glib_get_locale_dir (void) #endif /* G_OS_WIN32 */ static void -ensure_gettext_initialized(void) +ensure_gettext_initialized (void) { - static gboolean _glib_gettext_initialized = FALSE; + static gsize initialised; - if (!_glib_gettext_initialized) + g_thread_init_glib (); + + if (g_once_init_enter (&initialised)) { #ifdef G_OS_WIN32 gchar *tmp = _glib_get_locale_dir (); @@ -3723,7 +3716,7 @@ ensure_gettext_initialized(void) # ifdef HAVE_BIND_TEXTDOMAIN_CODESET bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); # endif - _glib_gettext_initialized = TRUE; + g_once_init_leave (&initialised, TRUE); } } -- 2.7.4