summaryrefslogtreecommitdiffstats
path: root/src/util/strtod.cpp
diff options
context:
space:
mode:
authorChia-I Wu <[email protected]>2014-08-20 14:40:24 +0800
committerKenneth Graunke <[email protected]>2014-10-30 02:26:19 -0700
commit61c3d493882440d4d8d01a12b7b83fce63d6a7c7 (patch)
tree40dade6b8758009b9e982231bcebcbfb85d43203 /src/util/strtod.cpp
parentb039dbfffd8eedef53a5ff9ae6b0ae09e6844d9c (diff)
util: initialize locale_t with a static object
_mesa_strtod and _mesa_strtof may be called from multiple threads. They need to be thread-safe. v2: platform checks are now done in configure.ac Signed-off-by: Chia-I Wu <[email protected]> Reviewed-by: Brian Paul <[email protected]> Reviewed-by: Ian Romanick <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src/util/strtod.cpp')
-rw-r--r--src/util/strtod.cpp18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/util/strtod.cpp b/src/util/strtod.cpp
index 2a3e8eb5294..2b4dd982a80 100644
--- a/src/util/strtod.cpp
+++ b/src/util/strtod.cpp
@@ -36,6 +36,12 @@
#include "strtod.h"
+#if defined(_GNU_SOURCE) && defined(HAVE_XLOCALE_H)
+static struct locale_initializer {
+ locale_initializer() { loc = newlocale(LC_CTYPE_MASK, "C", NULL); }
+ locale_t loc;
+} loc_init;
+#endif
/**
* Wrapper around strtod which uses the "C" locale so the decimal
@@ -45,11 +51,7 @@ double
_mesa_strtod(const char *s, char **end)
{
#if defined(_GNU_SOURCE) && defined(HAVE_XLOCALE_H)
- static locale_t loc = NULL;
- if (!loc) {
- loc = newlocale(LC_CTYPE_MASK, "C", NULL);
- }
- return strtod_l(s, end, loc);
+ return strtod_l(s, end, loc_init.loc);
#else
return strtod(s, end);
#endif
@@ -64,11 +66,7 @@ float
_mesa_strtof(const char *s, char **end)
{
#if defined(_GNU_SOURCE) && defined(HAVE_XLOCALE_H)
- static locale_t loc = NULL;
- if (!loc) {
- loc = newlocale(LC_CTYPE_MASK, "C", NULL);
- }
- return strtof_l(s, end, loc);
+ return strtof_l(s, end, loc_init.loc);
#elif defined(HAVE_STRTOF)
return strtof(s, end);
#else