[lazy] Use for C_locale

This commit is contained in:
Behdad Esfahbod 2018-08-12 17:42:16 -07:00
parent 747d2564e6
commit 6750ec692c
1 changed files with 31 additions and 31 deletions

View File

@ -28,6 +28,7 @@
#include "hb-private.hh" #include "hb-private.hh"
#include "hb-machinery-private.hh"
#include <locale.h> #include <locale.h>
#ifdef HAVE_XLOCALE_H #ifdef HAVE_XLOCALE_H
@ -730,47 +731,46 @@ parse_uint32 (const char **pp, const char *end, uint32_t *pv)
#ifdef USE_XLOCALE #ifdef USE_XLOCALE
static hb_atomic_ptr_t<HB_LOCALE_T> C_locale;
static void free_static_C_locale (void);
static struct hb_C_locale_lazy_loader_t : hb_lazy_loader_t<hb_remove_ptr_t<HB_LOCALE_T>::value,
hb_C_locale_lazy_loader_t>
{
static inline HB_LOCALE_T create (void)
{
HB_LOCALE_T C_locale = HB_CREATE_LOCALE ("C");
#ifdef HB_USE_ATEXIT #ifdef HB_USE_ATEXIT
static void atexit (free_static_C_locale);
free_C_locale (void) #endif
return C_locale;
}
static inline void destroy (HB_LOCALE_T p)
{
HB_FREE_LOCALE (p);
}
static inline HB_LOCALE_T get_null (void)
{
return nullptr;
}
} static_C_locale;
#ifdef HB_USE_ATEXIT
static
void free_static_C_locale (void)
{ {
retry: static_C_locale.free_instance ();
HB_LOCALE_T locale = C_locale.get ();
if (unlikely (!C_locale.cmpexch (locale, nullptr)))
goto retry;
if (locale)
HB_FREE_LOCALE (locale);
} }
#endif #endif
static HB_LOCALE_T static HB_LOCALE_T
get_C_locale (void) get_C_locale (void)
{ {
retry: return static_C_locale.get_unconst ();
HB_LOCALE_T C = C_locale.get ();
if (unlikely (!C))
{
C = HB_CREATE_LOCALE ("C");
if (unlikely (!C_locale.cmpexch (nullptr, C)))
{
HB_FREE_LOCALE (C);
goto retry;
}
#ifdef HB_USE_ATEXIT
atexit (free_C_locale); /* First person registers atexit() callback. */
#endif
}
return C;
} }
#endif #endif /* USE_XLOCALE */
static bool static bool
parse_float (const char **pp, const char *end, float *pv) parse_float (const char **pp, const char *end, float *pv)