summaryrefslogtreecommitdiff
path: root/perl.h
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2021-03-08 05:21:32 -0700
committerKarl Williamson <khw@cpan.org>2022-09-21 14:34:41 -0600
commit1118ec15947427988784e2ab16171203db9b9d3f (patch)
treec5e02999784342a7ead370223561fd631a024add /perl.h
parentdff607ef35caa67235b1379fe58f6c48b130faa6 (diff)
downloadperl-1118ec15947427988784e2ab16171203db9b9d3f.tar.gz
Add POSIX_SETLOCALE_LOCK/UNLOCK
This macro is used to surround raw setlocale() calls so that the return value in a global static buffer can be saved without interference with other threads.
Diffstat (limited to 'perl.h')
-rw-r--r--perl.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/perl.h b/perl.h
index 0495c16e3a..68349e6c01 100644
--- a/perl.h
+++ b/perl.h
@@ -7223,6 +7223,24 @@ the plain locale pragma without a parameter (S<C<use locale>>) is in effect.
#define gwLOCALE_LOCK LOCALE_LOCK_(0)
#define gwLOCALE_UNLOCK LOCALE_UNLOCK_
+/* setlocale() generally returns in a global static buffer, but not on Windows
+ * when operating in thread-safe mode */
+#if defined(WIN32) && defined(USE_THREAD_SAFE_LOCALE)
+# define POSIX_SETLOCALE_LOCK \
+ STMT_START { \
+ if (_configthreadlocale(0) == _DISABLE_PER_THREAD_LOCALE) \
+ gwLOCALE_LOCK; \
+ } STMT_END
+# define POSIX_SETLOCALE_UNLOCK \
+ STMT_START { \
+ if (_configthreadlocale(0) == _DISABLE_PER_THREAD_LOCALE) \
+ gwLOCALE_UNLOCK; \
+ } STMT_END
+#else
+# define POSIX_SETLOCALE_LOCK gwLOCALE_LOCK
+# define POSIX_SETLOCALE_UNLOCK gwLOCALE_UNLOCK
+#endif
+
#ifndef LC_NUMERIC_LOCK
# define LC_NUMERIC_LOCK(cond) NOOP
# define LC_NUMERIC_UNLOCK NOOP