[Mesa-dev] [PATCHv2 03/13] glsl: initialize locale_t with a static object

Ian Romanick idr at freedesktop.org
Wed Aug 13 12:00:48 PDT 2014


On 07/09/2014 12:47 AM, Chia-I Wu wrote:
> The compiler may be used by multiple contexts simultaneously and needs to be
> thread-safe.
> 
> Signed-off-by: Chia-I Wu <olv at lunarg.com>
> ---
>  src/glsl/strtod.cpp | 29 +++++++++++++++--------------
>  1 file changed, 15 insertions(+), 14 deletions(-)
> 
> diff --git a/src/glsl/strtod.cpp b/src/glsl/strtod.cpp
> index 5d4346b..1ac29ec 100644
> --- a/src/glsl/strtod.cpp
> +++ b/src/glsl/strtod.cpp
> @@ -35,6 +35,17 @@
>  
>  #include "strtod.h"
>  
> +#if defined(_GNU_SOURCE) && !defined(__CYGWIN__) && !defined(__FreeBSD__) && \
> +   !defined(__HAIKU__) && !defined(__UCLIBC__)
> +#define GLSL_HAVE_LOCALE_T
> +#endif

Could we just do this in configure.ac (or whatever the scons analog is)
instead?

> +
> +#ifdef GLSL_HAVE_LOCALE_T
> +static struct locale_initializer {
> +   locale_initializer() { loc = newlocale(LC_CTYPE_MASK, "C", NULL); }
> +   locale_t loc;
> +} loc_init;
> +#endif
>  
>  
>  /**
> @@ -44,13 +55,8 @@
>  double
>  glsl_strtod(const char *s, char **end)
>  {
> -#if defined(_GNU_SOURCE) && !defined(__CYGWIN__) && !defined(__FreeBSD__) && \
> -   !defined(__HAIKU__) && !defined(__UCLIBC__)
> -   static locale_t loc = NULL;
> -   if (!loc) {
> -      loc = newlocale(LC_CTYPE_MASK, "C", NULL);
> -   }
> -   return strtod_l(s, end, loc);
> +#ifdef GLSL_HAVE_LOCALE_T
> +   return strtod_l(s, end, loc_init.loc);
>  #else
>     return strtod(s, end);
>  #endif
> @@ -64,13 +70,8 @@ glsl_strtod(const char *s, char **end)
>  float
>  glsl_strtof(const char *s, char **end)
>  {
> -#if defined(_GNU_SOURCE) && !defined(__CYGWIN__) && !defined(__FreeBSD__) && \
> -   !defined(__HAIKU__) && !defined(__UCLIBC__)
> -   static locale_t loc = NULL;
> -   if (!loc) {
> -      loc = newlocale(LC_CTYPE_MASK, "C", NULL);
> -   }
> -   return strtof_l(s, end, loc);
> +#ifdef GLSL_HAVE_LOCALE_T
> +   return strtof_l(s, end, loc_init.loc);
>  #elif _XOPEN_SOURCE >= 600 || _ISOC99_SOURCE
>     return strtof(s, end);
>  #else
> 



More information about the mesa-dev mailing list