summaryrefslogtreecommitdiff
path: root/src/locale/newlocale.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2020-12-09 16:58:32 -0500
committerRich Felker <dalias@aerifal.cx>2020-12-09 16:58:32 -0500
commit37fcc13c12ade19c37a1a8ac80be4a14e21cff1e (patch)
treebf9b3460c0ca84c4abdaab1f276e6f6e6d676c1c /src/locale/newlocale.c
parentc53e9b239418eb3e0e8be256abd0f6ad7608bbcf (diff)
downloadmusl-37fcc13c12ade19c37a1a8ac80be4a14e21cff1e.tar.gz
lift locale lock out of internal __get_locale
this allows the lock to be shared with setlocale, eliminates repeated per-category lock/unlock in newlocale, and will allow the use of pthread_once in newlocale to be dropped (to be done separately).
Diffstat (limited to 'src/locale/newlocale.c')
-rw-r--r--src/locale/newlocale.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/locale/newlocale.c b/src/locale/newlocale.c
index d20a8489..8eee2e10 100644
--- a/src/locale/newlocale.c
+++ b/src/locale/newlocale.c
@@ -2,6 +2,7 @@
#include <string.h>
#include <pthread.h>
#include "locale_impl.h"
+#include "lock.h"
static pthread_once_t default_locale_once;
static struct __locale_struct default_locale, default_ctype_locale;
@@ -19,7 +20,7 @@ int __loc_is_allocated(locale_t loc)
&& loc != &default_locale && loc != &default_ctype_locale;
}
-locale_t __newlocale(int mask, const char *name, locale_t loc)
+static locale_t do_newlocale(int mask, const char *name, locale_t loc)
{
struct __locale_struct tmp;
@@ -55,4 +56,12 @@ locale_t __newlocale(int mask, const char *name, locale_t loc)
return loc;
}
+locale_t __newlocale(int mask, const char *name, locale_t loc)
+{
+ LOCK(__locale_lock);
+ loc = do_newlocale(mask, name, loc);
+ UNLOCK(__locale_lock);
+ return loc;
+}
+
weak_alias(__newlocale, newlocale);