mesa/main: rework locale setup/teardown
authorThong Thai <thong.thai@amd.com>
Wed, 26 Apr 2023 18:57:43 +0000 (14:57 -0400)
committerMarge Bot <emma+marge@anholt.net>
Thu, 27 Apr 2023 15:43:33 +0000 (15:43 +0000)
Cc: mesa-stable
Signed-off-by: Thong Thai <thong.thai@amd.com>
Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22699>

src/mesa/main/context.c
src/util/strtod.c

index f16d8ca..d8eea2e 100644 (file)
@@ -184,7 +184,6 @@ static void
 one_time_fini(void)
 {
    glsl_type_singleton_decref();
-   _mesa_locale_fini();
 }
 
 /**
index de695d6..b42dc2e 100644 (file)
@@ -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