mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-25 08:40:11 +01:00
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 <olv@lunarg.com> Reviewed-by: Brian Paul <brianp@vmware.com> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
This commit is contained in:
parent
b039dbfffd
commit
61c3d49388
1 changed files with 8 additions and 10 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue