about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2020-12-09 17:01:57 -0500
committerRich Felker <dalias@aerifal.cx>2020-12-09 17:01:57 -0500
commit36246b347cd135399bc79f9b6617d9a120c00a0d (patch)
tree3fcae115948830637a424fd1a0592135d813da7b /src
parent37fcc13c12ade19c37a1a8ac80be4a14e21cff1e (diff)
downloadmusl-36246b347cd135399bc79f9b6617d9a120c00a0d.tar.gz
musl-36246b347cd135399bc79f9b6617d9a120c00a0d.tar.xz
musl-36246b347cd135399bc79f9b6617d9a120c00a0d.zip
drop use of pthread_once in newlocale
in general, pthread_once is not compatible with MT-fork constraints
(commit 167390f05564e0a4d3fcb4329377fd7743267560). here it actually no
longer matters, because it's now called with a lock held, but since
the lock is held it's pointless to use pthread_once.
Diffstat (limited to 'src')
-rw-r--r--src/locale/newlocale.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/locale/newlocale.c b/src/locale/newlocale.c
index 8eee2e10..12ae87d6 100644
--- a/src/locale/newlocale.c
+++ b/src/locale/newlocale.c
@@ -4,16 +4,9 @@
 #include "locale_impl.h"
 #include "lock.h"
 
-static pthread_once_t default_locale_once;
+static int default_locale_init_done;
 static struct __locale_struct default_locale, default_ctype_locale;
 
-static void default_locale_init(void)
-{
-	for (int i=0; i<LC_ALL; i++)
-		default_locale.cat[i] = __get_locale(i, "");
-	default_ctype_locale.cat[LC_CTYPE] = default_locale.cat[LC_CTYPE];
-}
-
 int __loc_is_allocated(locale_t loc)
 {
 	return loc && loc != C_LOCALE && loc != UTF8_LOCALE
@@ -45,7 +38,12 @@ static locale_t do_newlocale(int mask, const char *name, locale_t loc)
 
 	/* And provide builtins for the initial default locale, and a
 	 * variant of the C locale honoring the default locale's encoding. */
-	pthread_once(&default_locale_once, default_locale_init);
+	if (!default_locale_init_done) {
+		for (int i=0; i<LC_ALL; i++)
+			default_locale.cat[i] = __get_locale(i, "");
+		default_ctype_locale.cat[LC_CTYPE] = default_locale.cat[LC_CTYPE];
+		default_locale_init_done = 1;
+	}
 	if (!memcmp(&tmp, &default_locale, sizeof tmp)) return &default_locale;
 	if (!memcmp(&tmp, &default_ctype_locale, sizeof tmp))
 		return &default_ctype_locale;