diff options
author | Rich Felker <dalias@aerifal.cx> | 2020-12-09 16:58:32 -0500 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2020-12-09 16:58:32 -0500 |
commit | 37fcc13c12ade19c37a1a8ac80be4a14e21cff1e (patch) | |
tree | bf9b3460c0ca84c4abdaab1f276e6f6e6d676c1c /src/locale/setlocale.c | |
parent | c53e9b239418eb3e0e8be256abd0f6ad7608bbcf (diff) | |
download | musl-37fcc13c12ade19c37a1a8ac80be4a14e21cff1e.tar.gz musl-37fcc13c12ade19c37a1a8ac80be4a14e21cff1e.tar.bz2 musl-37fcc13c12ade19c37a1a8ac80be4a14e21cff1e.tar.xz musl-37fcc13c12ade19c37a1a8ac80be4a14e21cff1e.zip |
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/setlocale.c')
-rw-r--r-- | src/locale/setlocale.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/locale/setlocale.c b/src/locale/setlocale.c index 2bc7b500..360c4437 100644 --- a/src/locale/setlocale.c +++ b/src/locale/setlocale.c @@ -9,12 +9,11 @@ static char buf[LC_ALL*(LOCALE_NAME_MAX+1)]; char *setlocale(int cat, const char *name) { - static volatile int lock[1]; const struct __locale_map *lm; if ((unsigned)cat > LC_ALL) return 0; - LOCK(lock); + LOCK(__locale_lock); /* For LC_ALL, setlocale is required to return a string which * encodes the current setting for all categories. The format of @@ -36,7 +35,7 @@ char *setlocale(int cat, const char *name) } lm = __get_locale(i, part); if (lm == LOC_MAP_FAILED) { - UNLOCK(lock); + UNLOCK(__locale_lock); return 0; } tmp_locale.cat[i] = lm; @@ -57,14 +56,14 @@ char *setlocale(int cat, const char *name) s += l+1; } *--s = 0; - UNLOCK(lock); + UNLOCK(__locale_lock); return same==LC_ALL ? (char *)part : buf; } if (name) { lm = __get_locale(cat, name); if (lm == LOC_MAP_FAILED) { - UNLOCK(lock); + UNLOCK(__locale_lock); return 0; } libc.global_locale.cat[cat] = lm; @@ -73,7 +72,7 @@ char *setlocale(int cat, const char *name) } char *ret = lm ? (char *)lm->name : "C"; - UNLOCK(lock); + UNLOCK(__locale_lock); return ret; } |