From 9ecc019d4d1934e6dd558a777f78b473ed92b127 Mon Sep 17 00:00:00 2001 From: Thong Thai Date: Wed, 26 Apr 2023 14:57:43 -0400 Subject: [PATCH] mesa/main: rework locale setup/teardown Cc: mesa-stable Signed-off-by: Thong Thai Acked-by: Pierre-Eric Pelloux-Prayer Part-of: (cherry picked from commit 7373f25c0934882250847fb292f977d2d5569642) --- .pick_status.json | 2 +- src/mesa/main/context.c | 1 - src/util/strtod.c | 14 +++++++++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index bcb21919c49..8d0214abf2c 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -958,7 +958,7 @@ "description": "mesa/main: rework locale setup/teardown", "nominated": true, "nomination_type": 0, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null }, diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c index f16d8caa63b..d8eea2ea867 100644 --- a/src/mesa/main/context.c +++ b/src/mesa/main/context.c @@ -184,7 +184,6 @@ static void one_time_fini(void) { glsl_type_singleton_decref(); - _mesa_locale_fini(); } /** diff --git a/src/util/strtod.c b/src/util/strtod.c index de695d64b47..b42dc2e55b9 100644 --- a/src/util/strtod.c +++ b/src/util/strtod.c @@ -35,14 +35,22 @@ static locale_t loc; #endif #include "strtod.h" +#include "util/u_call_once.h" +static void +_mesa_locale_init_once(void) +{ + #if defined(_GNU_SOURCE) && defined(HAVE_STRTOD_L) + loc = newlocale(LC_CTYPE_MASK, "C", NULL); + atexit(_mesa_locale_fini); + #endif +} void _mesa_locale_init(void) { -#if defined(_GNU_SOURCE) && defined(HAVE_STRTOD_L) - loc = newlocale(LC_CTYPE_MASK, "C", NULL); -#endif + static util_once_flag once = UTIL_ONCE_FLAG_INIT; + util_call_once(&once, _mesa_locale_init_once); } void