summaryrefslogtreecommitdiff
path: root/lib/localename-table.h
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2018-10-22 02:38:39 +0200
committerBruno Haible <bruno@clisp.org>2018-10-22 02:38:39 +0200
commitde62ab01a4b868acadc33ea6edec95d279664aa7 (patch)
treec5be9bf0986a4cb81e4a79082be55db38ae8cffe /lib/localename-table.h
parentff999a89d151ac2f43df80321e4ea88555bd81ec (diff)
downloadgnulib-de62ab01a4b868acadc33ea6edec95d279664aa7.tar.gz
localename: Fine-tune support for per-thread locales on Solaris 11.4.
* lib/localename-table.h: New file, extracted from lib/localename.c. * lib/localename-table.c: Likewise. * lib/localename.c: Include localename-table.h. (get_locale_t_name, newlocale, duplocale, freelocale): Invoke locale_hash_function instead of pointer_hash. * modules/localename (Files): Add lib/localename-table.h, lib/localename-table.c. (lib_SOURCES): Add localename-table.c. * m4/intlsolaris.m4 (gt_INTL_SOLARIS): Require AC_CANONICAL_HOST. Test for Solaris 11.4 locale system only on Solaris. Test for it independently whether getlocalename_l exists. * m4/intl.m4 (gt_INTL_SUBDIR_CORE): Don't test for 'uselocale' and 'getlocalename_l'. Instead, invoke gt_INTL_SOLARIS. Set HAVE_NAMELESS_LOCALES. * modules/gettext (Files): Add m4/intlsolaris.m4.
Diffstat (limited to 'lib/localename-table.h')
-rw-r--r--lib/localename-table.h73
1 files changed, 73 insertions, 0 deletions
diff --git a/lib/localename-table.h b/lib/localename-table.h
new file mode 100644
index 0000000000..0d204d6d14
--- /dev/null
+++ b/lib/localename-table.h
@@ -0,0 +1,73 @@
+/* Table that maps a locale object to the names of the locale categories.
+ Copyright (C) 2018 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2018. */
+
+#if HAVE_USELOCALE && HAVE_NAMELESS_LOCALES /* Solaris >= 11.4 */
+
+# include <stddef.h>
+# include <locale.h>
+
+# ifdef IN_LIBINTL
+# include "lock.h"
+# else
+# include "glthread/lock.h"
+# endif
+
+struct locale_categories_names
+ {
+ /* Locale category -> name (allocated with indefinite extent). */
+ const char *category_name[6];
+ };
+
+/* A hash table of fixed size. Multiple threads can access it read-only
+ simultaneously, but only one thread can insert into it or remove from it
+ at the same time.
+ This hash table has global scope, so that when an application uses both
+ GNU libintl and gnulib, the application sees only one hash table. (When
+ linking statically with libintl, the fact that localename-table.c is a
+ separate compilation unit resolves the duplicate symbol conflict. When
+ linking with libintl as a shared library, we rely on ELF and the symbol
+ conflict resolution implemented in the ELF dynamic loader here.)
+ Both the libintl overrides and the gnulib overrides of the functions
+ newlocale, duplocale, freelocale see the same hash table (and the same lock).
+ For this reason, the internal layout of the hash table and the hash function
+ MUST NEVER CHANGE. If you need to change the internal layout or the hash
+ function, introduce versioning by appending a version suffix to the symbols
+ at the linker level. */
+# define locale_hash_function libintl_locale_hash_function
+# define locale_hash_table libintl_locale_hash_table
+# define locale_lock libintl_locale_lock
+
+extern size_t _GL_ATTRIBUTE_CONST locale_hash_function (locale_t x);
+
+/* A node in a hash bucket collision list. */
+struct locale_hash_node
+ {
+ struct locale_hash_node *next;
+ locale_t locale;
+ struct locale_categories_names names;
+ };
+
+# define LOCALE_HASH_TABLE_SIZE 101
+extern struct locale_hash_node * locale_hash_table[LOCALE_HASH_TABLE_SIZE];
+
+/* This lock protects the locale_hash_table against multiple simultaneous
+ accesses (except that multiple simultaneous read accesses are allowed). */
+
+gl_rwlock_define(extern, locale_lock)
+
+#endif