提交 04aed572 编写于 作者: B Behdad Esfahbod

Make hb-ft static-initializer free

上级 be4560a3
...@@ -182,7 +182,6 @@ void free_langs (void) ...@@ -182,7 +182,6 @@ void free_langs (void)
static hb_language_item_t * static hb_language_item_t *
lang_find_or_insert (const char *key) lang_find_or_insert (const char *key)
{ {
retry: retry:
hb_language_item_t *first_lang = (hb_language_item_t *) hb_atomic_ptr_get (&langs); hb_language_item_t *first_lang = (hb_language_item_t *) hb_atomic_ptr_get (&langs);
...@@ -203,8 +202,8 @@ retry: ...@@ -203,8 +202,8 @@ retry:
} }
#ifdef HAVE_ATEXIT #ifdef HAVE_ATEXIT
if (!first_lang) /* First person registers atexit() callback. */ if (!first_lang)
atexit (free_langs); atexit (free_langs); /* First person registers atexit() callback. */
#endif #endif
return lang; return lang;
......
...@@ -398,21 +398,37 @@ hb_ft_font_create (FT_Face ft_face, ...@@ -398,21 +398,37 @@ hb_ft_font_create (FT_Face ft_face,
} }
static FT_Library ft_library;
static
void free_ft_library (void)
{
FT_Done_FreeType (ft_library);
}
static FT_Library static FT_Library
_get_ft_library (void) get_ft_library (void)
{ {
static struct ft_library_singleton retry:
FT_Library library = (FT_Library) hb_atomic_ptr_get (&ft_library);
if (unlikely (!library))
{ {
ft_library_singleton (void) { /* Not found; allocate one. */
FT_Init_FreeType (&ft_library); if (FT_Init_FreeType (&library))
} return NULL;
~ft_library_singleton (void) {
FT_Done_FreeType (ft_library); if (!hb_atomic_ptr_cmpexch (&ft_library, NULL, library)) {
FT_Done_FreeType (library);
goto retry;
} }
FT_Library ft_library;
} ft_library_singleton;
return ft_library_singleton.ft_library; #ifdef HAVE_ATEXIT
atexit (free_ft_library); /* First person registers atexit() callback. */
#endif
}
return library;
} }
static void static void
...@@ -431,7 +447,7 @@ hb_ft_font_set_funcs (hb_font_t *font) ...@@ -431,7 +447,7 @@ hb_ft_font_set_funcs (hb_font_t *font)
DEBUG_MSG (FT, font, "Font face has empty blob"); DEBUG_MSG (FT, font, "Font face has empty blob");
FT_Face ft_face = NULL; FT_Face ft_face = NULL;
FT_Error err = FT_New_Memory_Face (_get_ft_library (), FT_Error err = FT_New_Memory_Face (get_ft_library (),
(const FT_Byte *) blob_data, (const FT_Byte *) blob_data,
blob_length, blob_length,
hb_face_get_index (font->face), hb_face_get_index (font->face),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册