Skip to content

Commit

Permalink
Rename SETLOCALE_LOCK to LOCALE_LOCK
Browse files Browse the repository at this point in the history
This mutex isn't just about the setlocale function; it applies to all
locale related critical sections.
  • Loading branch information
khwilliamson committed May 6, 2023
1 parent 613af8d commit 14d5080
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 deletions locale.c
Expand Up @@ -6960,15 +6960,15 @@ Perl_my_strerror(pTHX_ const int errnum, utf8ness_t * utf8ness)
}
else {

SETLOCALE_LOCK;
LOCALE_LOCK;

const char * orig_locale = toggle_locale_i(WHICH_LC_INDEX, "C");

errstr = savepv(Strerror(errnum));

restore_toggled_locale_i(WHICH_LC_INDEX, orig_locale);

SETLOCALE_UNLOCK;
LOCALE_UNLOCK;

*utf8ness = UTF8NESS_IMMATERIAL;

Expand Down Expand Up @@ -6998,7 +6998,7 @@ Perl_my_strerror(pTHX_ const int errnum, utf8ness_t * utf8ness)
: "C";
/* XXX Can fail on z/OS */

SETLOCALE_LOCK;
LOCALE_LOCK;

const char* orig_CTYPE_locale = toggle_locale_c(LC_CTYPE, desired_locale);
const char* orig_MESSAGES_locale = toggle_locale_c(LC_MESSAGES,
Expand All @@ -7008,7 +7008,7 @@ Perl_my_strerror(pTHX_ const int errnum, utf8ness_t * utf8ness)
restore_toggled_locale_c(LC_MESSAGES, orig_MESSAGES_locale);
restore_toggled_locale_c(LC_CTYPE, orig_CTYPE_locale);

SETLOCALE_UNLOCK;
LOCALE_UNLOCK;

*utf8ness = get_locale_string_utf8ness_i(errstr, LOCALE_UTF8NESS_UNKNOWN,
NULL, LC_MESSAGES_INDEX_);
Expand Down
26 changes: 13 additions & 13 deletions perl.h
Expand Up @@ -7160,8 +7160,8 @@ the plain locale pragma without a parameter (S<C<use locale>>) is in effect.

/* By definition, a thread-unsafe locale means we need a critical
* section. */
# define SETLOCALE_LOCK LOCALE_LOCK_(0)
# define SETLOCALE_UNLOCK LOCALE_UNLOCK_
# define LOCALE_LOCK LOCALE_LOCK_(0)
# define LOCALE_UNLOCK LOCALE_UNLOCK_
# ifdef USE_LOCALE_NUMERIC
# define LC_NUMERIC_LOCK(cond_to_panic_if_already_locked) \
LOCALE_LOCK_(cond_to_panic_if_already_locked)
Expand Down Expand Up @@ -7264,23 +7264,23 @@ the plain locale pragma without a parameter (S<C<use locale>>) is in effect.
* could change out from under us, we use an exclusive LOCALE lock to prevent
* that, and a read ENV lock to prevent other threads that have nothing to do
* with locales here from changing the environment. */
#ifdef SETLOCALE_LOCK
#ifdef LOCALE_LOCK
# define gwENVr_LOCALEr_LOCK \
STMT_START { SETLOCALE_LOCK; ENV_READ_LOCK; } STMT_END
STMT_START { LOCALE_LOCK; ENV_READ_LOCK; } STMT_END
# define gwENVr_LOCALEr_UNLOCK \
STMT_START { ENV_READ_UNLOCK; SETLOCALE_UNLOCK; } STMT_END
STMT_START { ENV_READ_UNLOCK; LOCALE_UNLOCK; } STMT_END
#else
# define gwENVr_LOCALEr_LOCK ENV_LOCK
# define gwENVr_LOCALEr_UNLOCK ENV_UNLOCK
#endif

/* Now that we have defined gwENVr_LOCALEr_LOCK, we can finish defining
* SETLOCALE_LOCK, which we kept undefined until here on a thread-safe system
* LOCALE_LOCK, which we kept undefined until here on a thread-safe system
* so that we could use that fact to calculate what gwENVr_LOCALEr_LOCK should
* be */
#ifndef SETLOCALE_LOCK
# define SETLOCALE_LOCK NOOP
# define SETLOCALE_UNLOCK NOOP
#ifndef LOCALE_LOCK
# define LOCALE_LOCK NOOP
# define LOCALE_UNLOCK NOOP
#endif


Expand All @@ -7290,8 +7290,8 @@ the plain locale pragma without a parameter (S<C<use locale>>) is in effect.
* exclusive lock. By defining it here with this name, we can, for the
* most part, hide this detail from the rest of the code */
/* Currently, the read lock is an exclusive lock */
#define LOCALE_READ_LOCK SETLOCALE_LOCK
#define LOCALE_READ_UNLOCK SETLOCALE_UNLOCK
#define LOCALE_READ_LOCK LOCALE_LOCK
#define LOCALE_READ_UNLOCK LOCALE_UNLOCK


#ifndef LC_NUMERIC_LOCK
Expand Down Expand Up @@ -7319,8 +7319,8 @@ the plain locale pragma without a parameter (S<C<use locale>>) is in effect.
# define WCRTOMB_LOCK_ NOOP
# define WCRTOMB_UNLOCK_ NOOP

# define LC_COLLATE_LOCK SETLOCALE_LOCK
# define LC_COLLATE_UNLOCK SETLOCALE_UNLOCK
# define LC_COLLATE_LOCK LOCALE_LOCK
# define LC_COLLATE_UNLOCK LOCALE_UNLOCK

# define STRFTIME_LOCK ENV_LOCK
# define STRFTIME_UNLOCK ENV_UNLOCK
Expand Down

0 comments on commit 14d5080

Please sign in to comment.