Skip to content

Commit

Permalink
perl.h Move locale mutex init/destruct
Browse files Browse the repository at this point in the history
I can't find a place in this file for this to go that isn't somewhat
awkward.  Because the environment and locale mutexes are intertwined,
they naturally fit together.  One would think the basic initialization
and termination of the locale mutexes should go ahead of their use.  But
because of all the complications, that interrupts the flow of the logic
between the environment and locale mutexes, so this commit moves them to
later in the file.
  • Loading branch information
khwilliamson committed Mar 12, 2024
1 parent 398eeab commit 180929b
Showing 1 changed file with 33 additions and 31 deletions.
64 changes: 33 additions & 31 deletions perl.h
Expand Up @@ -7053,9 +7053,6 @@ typedef struct am_table_short AMTS;
#if ! defined(USE_LOCALE_THREADS) /* No threads, or no locales */
# define LOCALE_LOCK_(cond) NOOP
# define LOCALE_UNLOCK_ NOOP
# define LOCALE_INIT
# define LOCALE_TERM

#else /* Below: Threaded, and locales are supported */

/* A locale mutex is required on all such threaded builds for at least
Expand Down Expand Up @@ -7087,34 +7084,6 @@ typedef struct am_table_short AMTS;
# define LC_NUMERIC_UNLOCK LOCALE_UNLOCK_
# endif
# endif

# ifdef WIN32_USE_FAKE_OLD_MINGW_LOCALES
/* This function is coerced by this Configure option into cleaning up
* memory that is static to locale.c. So we call it at termination. Doing
* it this way is kludgy but confines having to deal with this
* Configuration to a bare minimum number of places. */
# define LOCALE_TERM_POSIX_2008_ Perl_thread_locale_term(NULL)
# elif ! defined(USE_POSIX_2008_LOCALE)
# define LOCALE_TERM_POSIX_2008_ NOOP
# else
/* We have a locale object holding the 'C' locale for Posix 2008 */
# define LOCALE_TERM_POSIX_2008_ \
STMT_START { \
if (PL_C_locale_obj) { \
/* Make sure we aren't using the locale \
* space we are about to free */ \
uselocale(LC_GLOBAL_LOCALE); \
freelocale(PL_C_locale_obj); \
PL_C_locale_obj = (locale_t) NULL; \
} \
} STMT_END
# endif

# define LOCALE_INIT MUTEX_INIT(&PL_locale_mutex)
# define LOCALE_TERM STMT_START { \
LOCALE_TERM_POSIX_2008_; \
MUTEX_DESTROY(&PL_locale_mutex); \
} STMT_END
#endif

/* There are some locale-related functions which may need locking only because
Expand Down Expand Up @@ -7379,6 +7348,39 @@ typedef struct am_table_short AMTS;

/* End of locale/env synchronization */

#if ! defined(USE_LOCALE_THREADS)
# define LOCALE_INIT
# define LOCALE_TERM
#else
# ifdef WIN32_USE_FAKE_OLD_MINGW_LOCALES
/* This function is coerced by this Configure option into cleaning up
* memory that is static to locale.c. So we call it at termination. Doing
* it this way is kludgy but confines having to deal with this
* Configuration to a bare minimum number of places. */
# define LOCALE_TERM_POSIX_2008_ Perl_thread_locale_term(NULL)
# elif ! defined(USE_POSIX_2008_LOCALE)
# define LOCALE_TERM_POSIX_2008_ NOOP
# else
/* We have a locale object holding the 'C' locale for Posix 2008 */
# define LOCALE_TERM_POSIX_2008_ \
STMT_START { \
if (PL_C_locale_obj) { \
/* Make sure we aren't using the locale \
* space we are about to free */ \
uselocale(LC_GLOBAL_LOCALE); \
freelocale(PL_C_locale_obj); \
PL_C_locale_obj = (locale_t) NULL; \
} \
} STMT_END
# endif

# define LOCALE_INIT MUTEX_INIT(&PL_locale_mutex)
# define LOCALE_TERM STMT_START { \
LOCALE_TERM_POSIX_2008_; \
MUTEX_DESTROY(&PL_locale_mutex); \
} STMT_END
#endif

#ifdef USE_LOCALE /* These locale things are all subject to change */

/* Returns TRUE if the plain locale pragma without a parameter is in effect.
Expand Down

0 comments on commit 180929b

Please sign in to comment.