Make atexit callbacks threadsafe (#930)
This commit is contained in:
parent
d3a432a7b2
commit
70d36543aa
|
@ -724,8 +724,14 @@ static HB_LOCALE_T C_locale;
|
|||
static void
|
||||
free_C_locale (void)
|
||||
{
|
||||
if (C_locale)
|
||||
HB_FREE_LOCALE (C_locale);
|
||||
retry:
|
||||
HB_LOCALE_T locale = (HB_LOCALE_T) hb_atomic_ptr_get (&C_locale);
|
||||
|
||||
if (!hb_atomic_ptr_cmpexch (&C_locale, locale, nullptr))
|
||||
goto retry;
|
||||
|
||||
if (locale)
|
||||
HB_FREE_LOCALE (locale);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
14
src/hb-ft.cc
14
src/hb-ft.cc
|
@ -423,7 +423,12 @@ static hb_font_funcs_t *static_ft_funcs = nullptr;
|
|||
static
|
||||
void free_static_ft_funcs (void)
|
||||
{
|
||||
hb_font_funcs_destroy (static_ft_funcs);
|
||||
retry:
|
||||
hb_font_funcs_t *ft_funcs = (hb_font_funcs_t *) hb_atomic_ptr_get (&static_ft_funcs);
|
||||
if (!hb_atomic_ptr_cmpexch (&static_ft_funcs, ft_funcs, nullptr))
|
||||
goto retry;
|
||||
|
||||
hb_font_funcs_destroy (ft_funcs);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -685,7 +690,12 @@ static FT_Library ft_library;
|
|||
static
|
||||
void free_ft_library (void)
|
||||
{
|
||||
FT_Done_FreeType (ft_library);
|
||||
retry:
|
||||
FT_Library library = (FT_Library) hb_atomic_ptr_get (&ft_library);
|
||||
if (!hb_atomic_ptr_cmpexch (&ft_library, library, nullptr))
|
||||
goto retry;
|
||||
|
||||
FT_Done_FreeType (library);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -370,7 +370,12 @@ static hb_unicode_funcs_t *static_glib_funcs = nullptr;
|
|||
static
|
||||
void free_static_glib_funcs (void)
|
||||
{
|
||||
hb_unicode_funcs_destroy (static_glib_funcs);
|
||||
retry:
|
||||
hb_unicode_funcs_t *glib_funcs = (hb_unicode_funcs_t *) hb_atomic_ptr_get (&static_glib_funcs);
|
||||
if (!hb_atomic_ptr_cmpexch (&static_glib_funcs, glib_funcs, nullptr))
|
||||
goto retry;
|
||||
|
||||
hb_unicode_funcs_destroy (glib_funcs);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -351,7 +351,12 @@ static hb_unicode_funcs_t *static_icu_funcs = nullptr;
|
|||
static
|
||||
void free_static_icu_funcs (void)
|
||||
{
|
||||
hb_unicode_funcs_destroy (static_icu_funcs);
|
||||
retry:
|
||||
hb_unicode_funcs_t *icu_funcs = (hb_unicode_funcs_t *) hb_atomic_ptr_get (&static_icu_funcs);
|
||||
if (!hb_atomic_ptr_cmpexch (&static_icu_funcs, icu_funcs, nullptr))
|
||||
goto retry;
|
||||
|
||||
hb_unicode_funcs_destroy (icu_funcs);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -217,7 +217,12 @@ static hb_font_funcs_t *static_ot_funcs = nullptr;
|
|||
static
|
||||
void free_static_ot_funcs (void)
|
||||
{
|
||||
hb_font_funcs_destroy (static_ot_funcs);
|
||||
retry:
|
||||
hb_font_funcs_t *ot_funcs = (hb_font_funcs_t *) hb_atomic_ptr_get (&static_ot_funcs);
|
||||
if (!hb_atomic_ptr_cmpexch (&static_ot_funcs, ot_funcs, nullptr))
|
||||
goto retry;
|
||||
|
||||
hb_font_funcs_destroy (ot_funcs);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -51,7 +51,12 @@ static const char **static_shaper_list;
|
|||
static
|
||||
void free_static_shaper_list (void)
|
||||
{
|
||||
free (static_shaper_list);
|
||||
retry:
|
||||
const char **shaper_list = (const char **) hb_atomic_ptr_get (&static_shaper_list);
|
||||
if (!hb_atomic_ptr_cmpexch (&static_shaper_list, shaper_list, nullptr))
|
||||
goto retry;
|
||||
|
||||
free (shaper_list);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -44,8 +44,13 @@ static const hb_shaper_pair_t *static_shapers;
|
|||
static
|
||||
void free_static_shapers (void)
|
||||
{
|
||||
if (unlikely (static_shapers != all_shapers))
|
||||
free ((void *) static_shapers);
|
||||
retry:
|
||||
hb_shaper_pair_t *shapers = (hb_shaper_pair_t *) hb_atomic_ptr_get (&static_shapers);
|
||||
if (!hb_atomic_ptr_cmpexch (&static_shapers, shapers, nullptr))
|
||||
goto retry;
|
||||
|
||||
if (unlikely (shapers != all_shapers))
|
||||
free ((void *) shapers);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -237,7 +237,12 @@ static hb_unicode_funcs_t *static_ucdn_funcs = nullptr;
|
|||
static
|
||||
void free_static_ucdn_funcs (void)
|
||||
{
|
||||
hb_unicode_funcs_destroy (static_ucdn_funcs);
|
||||
retry:
|
||||
hb_unicode_funcs_t *ucdn_funcs = (hb_unicode_funcs_t *) hb_atomic_ptr_get (&static_ucdn_funcs);
|
||||
if (!hb_atomic_ptr_cmpexch (&static_ucdn_funcs, ucdn_funcs, nullptr))
|
||||
goto retry;
|
||||
|
||||
hb_unicode_funcs_destroy (ucdn_funcs);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -223,11 +223,19 @@ struct hb_uniscribe_shaper_funcs_t {
|
|||
};
|
||||
static hb_uniscribe_shaper_funcs_t *uniscribe_funcs;
|
||||
|
||||
#ifdef HB_USE_ATEXIT
|
||||
static inline void
|
||||
free_uniscribe_funcs (void)
|
||||
{
|
||||
retry:
|
||||
hb_uniscribe_shaper_funcs_t *local_uniscribe_funcs =
|
||||
(hb_uniscribe_shaper_funcs_t *) hb_atomic_ptr_get (&uniscribe_funcs);
|
||||
if (!hb_atomic_ptr_cmpexch (&uniscribe_funcs, local_uniscribe_funcs, nullptr))
|
||||
goto retry;
|
||||
|
||||
free (uniscribe_funcs);
|
||||
}
|
||||
#endif
|
||||
|
||||
static hb_uniscribe_shaper_funcs_t *
|
||||
hb_uniscribe_shaper_get_funcs (void)
|
||||
|
|
Loading…
Reference in New Issue