#include "hb-ft.h"
#include "hb-font-private.hh"
+#include "hb-machinery-private.hh"
#include FT_ADVANCES_H
#include FT_MULTIPLE_MASTERS_H
return true;
}
-static hb_atomic_ptr_t<hb_font_funcs_t> static_ft_funcs;
+static void free_static_ft_funcs (void);
-#ifdef HB_USE_ATEXIT
-static
-void free_static_ft_funcs (void)
-{
-retry:
- hb_font_funcs_t *ft_funcs = static_ft_funcs.get ();
- if (unlikely (!static_ft_funcs.cmpexch (ft_funcs, nullptr)))
- goto retry;
-
- hb_font_funcs_destroy (ft_funcs);
-}
-#endif
-
-static void
-_hb_ft_font_set_funcs (hb_font_t *font, FT_Face ft_face, bool unref)
+static struct hb_ft_font_funcs_lazy_loader_t : hb_font_funcs_lazy_loader_t<hb_ft_font_funcs_lazy_loader_t>
{
-retry:
- hb_font_funcs_t *funcs = static_ft_funcs.get ();
-
- if (unlikely (!funcs))
+ static inline hb_font_funcs_t *create (void)
{
- funcs = hb_font_funcs_create ();
+ hb_font_funcs_t *funcs = hb_font_funcs_create ();
hb_font_funcs_set_font_h_extents_func (funcs, hb_ft_get_font_h_extents, nullptr, nullptr);
//hb_font_funcs_set_font_v_extents_func (funcs, hb_ft_get_font_v_extents, nullptr, nullptr);
hb_font_funcs_make_immutable (funcs);
- if (unlikely (!static_ft_funcs. cmpexch (nullptr, funcs)))
- {
- hb_font_funcs_destroy (funcs);
- goto retry;
- }
+#ifdef HB_USE_ATEXIT
+ atexit (free_static_ft_funcs);
+#endif
+
+ return funcs;
+ }
+} static_ft_funcs;
#ifdef HB_USE_ATEXIT
- atexit (free_static_ft_funcs); /* First person registers atexit() callback. */
+static
+void free_static_ft_funcs (void)
+{
+ static_ft_funcs.fini ();
+}
#endif
- };
+static hb_font_funcs_t *
+_hb_ft_get_font_funcs (void)
+{
+ return const_cast<hb_font_funcs_t *> (static_ft_funcs.get ());
+}
+
+static void
+_hb_ft_font_set_funcs (hb_font_t *font, FT_Face ft_face, bool unref)
+{
bool symbol = ft_face->charmap && ft_face->charmap->encoding == FT_ENCODING_MS_SYMBOL;
hb_font_set_funcs (font,
- funcs,
+ _hb_ft_get_font_funcs (),
_hb_ft_font_create (ft_face, symbol, unref),
_hb_ft_font_destroy);
}
};
template <typename Subclass>
+struct hb_font_funcs_lazy_loader_t : hb_lazy_loader_t<Subclass,
+ void, 0,
+ hb_font_funcs_t>
+{
+ static inline void destroy (hb_font_funcs_t *p)
+ {
+ hb_font_funcs_destroy (p);
+ }
+ static inline const hb_font_funcs_t *get_null (void)
+ {
+ return hb_font_funcs_get_empty ();
+ }
+};
+template <typename Subclass>
struct hb_unicode_funcs_lazy_loader_t : hb_lazy_loader_t<Subclass,
void, 0,
hb_unicode_funcs_t>
#include "hb-ot.h"
#include "hb-font-private.hh"
+#include "hb-machinery-private.hh"
#include "hb-ot-cmap-table.hh"
#include "hb-ot-glyf-table.hh"
return ot_font->v_metrics.has_font_extents;
}
-static hb_atomic_ptr_t <hb_font_funcs_t> static_ot_funcs;
-#ifdef HB_USE_ATEXIT
-static
-void free_static_ot_funcs (void)
-{
-retry:
- hb_font_funcs_t *ot_funcs = static_ot_funcs.get ();
- if (unlikely (!static_ot_funcs.cmpexch (ot_funcs, nullptr)))
- goto retry;
+static void free_static_ot_funcs (void);
- hb_font_funcs_destroy (ot_funcs);
-}
-#endif
-
-static hb_font_funcs_t *
-_hb_ot_get_font_funcs (void)
+static struct hb_ot_font_funcs_lazy_loader_t : hb_font_funcs_lazy_loader_t<hb_ot_font_funcs_lazy_loader_t>
{
-retry:
- hb_font_funcs_t *funcs = static_ot_funcs.get ();
-
- if (unlikely (!funcs))
+ static inline hb_font_funcs_t *create (void)
{
- funcs = hb_font_funcs_create ();
+ hb_font_funcs_t *funcs = hb_font_funcs_create ();
hb_font_funcs_set_font_h_extents_func (funcs, hb_ot_get_font_h_extents, nullptr, nullptr);
hb_font_funcs_set_font_v_extents_func (funcs, hb_ot_get_font_v_extents, nullptr, nullptr);
hb_font_funcs_make_immutable (funcs);
- if (unlikely (!static_ot_funcs.cmpexch (nullptr, funcs)))
- {
- hb_font_funcs_destroy (funcs);
- goto retry;
- }
+#ifdef HB_USE_ATEXIT
+ atexit (free_static_ot_funcs);
+#endif
+
+ return funcs;
+ }
+} static_ot_funcs;
#ifdef HB_USE_ATEXIT
- atexit (free_static_ot_funcs); /* First person registers atexit() callback. */
+static
+void free_static_ot_funcs (void)
+{
+ static_ot_funcs.fini ();
+}
#endif
- };
- return funcs;
+static hb_font_funcs_t *
+_hb_ot_get_font_funcs (void)
+{
+ return const_cast<hb_font_funcs_t *> (static_ot_funcs.get ());
}