Blame gnulib/tests/localename-table.h

Packit Service a2ae7a
/* Table that maps a locale object to the names of the locale categories.
Packit Service a2ae7a
   Copyright (C) 2018-2019 Free Software Foundation, Inc.
Packit Service a2ae7a
Packit Service a2ae7a
   This program is free software: you can redistribute it and/or modify
Packit Service a2ae7a
   it under the terms of the GNU General Public License as published by
Packit Service a2ae7a
   the Free Software Foundation; either version 3 of the License, or
Packit Service a2ae7a
   (at your option) any later version.
Packit Service a2ae7a
Packit Service a2ae7a
   This program is distributed in the hope that it will be useful,
Packit Service a2ae7a
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service a2ae7a
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service a2ae7a
   GNU General Public License for more details.
Packit Service a2ae7a
Packit Service a2ae7a
   You should have received a copy of the GNU General Public License
Packit Service a2ae7a
   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
Packit Service a2ae7a
Packit Service a2ae7a
/* Written by Bruno Haible <bruno@clisp.org>, 2018.  */
Packit Service a2ae7a
Packit Service a2ae7a
#if HAVE_WORKING_USELOCALE && HAVE_NAMELESS_LOCALES
Packit Service a2ae7a
Packit Service a2ae7a
# include <stddef.h>
Packit Service a2ae7a
# include <locale.h>
Packit Service a2ae7a
Packit Service a2ae7a
# ifdef IN_LIBINTL
Packit Service a2ae7a
#  include "lock.h"
Packit Service a2ae7a
# else
Packit Service a2ae7a
#  include "glthread/lock.h"
Packit Service a2ae7a
# endif
Packit Service a2ae7a
Packit Service a2ae7a
struct locale_categories_names
Packit Service a2ae7a
  {
Packit Service a2ae7a
    /* Locale category -> name (allocated with indefinite extent).  */
Packit Service a2ae7a
    const char *category_name[6];
Packit Service a2ae7a
  };
Packit Service a2ae7a
Packit Service a2ae7a
/* A hash table of fixed size.  Multiple threads can access it read-only
Packit Service a2ae7a
   simultaneously, but only one thread can insert into it or remove from it
Packit Service a2ae7a
   at the same time.
Packit Service a2ae7a
   This hash table has global scope, so that when an application uses both
Packit Service a2ae7a
   GNU libintl and gnulib, the application sees only one hash table.  (When
Packit Service a2ae7a
   linking statically with libintl, the fact that localename-table.c is a
Packit Service a2ae7a
   separate compilation unit resolves the duplicate symbol conflict.  When
Packit Service a2ae7a
   linking with libintl as a shared library, we rely on ELF and the symbol
Packit Service a2ae7a
   conflict resolution implemented in the ELF dynamic loader here.)
Packit Service a2ae7a
   Both the libintl overrides and the gnulib overrides of the functions
Packit Service a2ae7a
   newlocale, duplocale, freelocale see the same hash table (and the same lock).
Packit Service a2ae7a
   For this reason, the internal layout of the hash table and the hash function
Packit Service a2ae7a
   MUST NEVER CHANGE.  If you need to change the internal layout or the hash
Packit Service a2ae7a
   function, introduce versioning by appending a version suffix to the symbols
Packit Service a2ae7a
   at the linker level.  */
Packit Service a2ae7a
# define locale_hash_function libintl_locale_hash_function
Packit Service a2ae7a
# define locale_hash_table libintl_locale_hash_table
Packit Service a2ae7a
# define locale_lock libintl_locale_lock
Packit Service a2ae7a
Packit Service a2ae7a
extern size_t _GL_ATTRIBUTE_CONST locale_hash_function (locale_t x);
Packit Service a2ae7a
Packit Service a2ae7a
/* A node in a hash bucket collision list.  */
Packit Service a2ae7a
struct locale_hash_node
Packit Service a2ae7a
  {
Packit Service a2ae7a
    struct locale_hash_node *next;
Packit Service a2ae7a
    locale_t locale;
Packit Service a2ae7a
    struct locale_categories_names names;
Packit Service a2ae7a
  };
Packit Service a2ae7a
Packit Service a2ae7a
# define LOCALE_HASH_TABLE_SIZE 101
Packit Service a2ae7a
extern struct locale_hash_node * locale_hash_table[LOCALE_HASH_TABLE_SIZE];
Packit Service a2ae7a
Packit Service a2ae7a
/* This lock protects the locale_hash_table against multiple simultaneous
Packit Service a2ae7a
   accesses (except that multiple simultaneous read accesses are allowed).  */
Packit Service a2ae7a
Packit Service a2ae7a
gl_rwlock_define(extern, locale_lock)
Packit Service a2ae7a
Packit Service a2ae7a
#endif