[HarfBuzz] harfbuzz: Branch 'master'
Behdad Esfahbod
behdad at kemper.freedesktop.org
Mon Aug 13 01:21:25 UTC 2018
src/hb-uniscribe.cc | 56 ++++++++++++++++++++++++++--------------------------
1 file changed, 29 insertions(+), 27 deletions(-)
New commits:
commit 9bbd1cdf068635f4a737f1fc9ab54ba075601a5d
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Aug 12 18:20:53 2018 -0700
[uniscribe] Use lazy loader
Fixes https://github.com/harfbuzz/harfbuzz/issues/1129
diff --git a/src/hb-uniscribe.cc b/src/hb-uniscribe.cc
index 5810977d..11b7384f 100644
--- a/src/hb-uniscribe.cc
+++ b/src/hb-uniscribe.cc
@@ -221,47 +221,49 @@ struct hb_uniscribe_shaper_funcs_t
}
}
};
-static hb_atomic_ptr_t<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 = uniscribe_funcs.get ();
- if (unlikely (!uniscribe_funcs.cmpexch (local_uniscribe_funcs, nullptr)))
- goto retry;
- free (local_uniscribe_funcs);
-}
-#endif
+static void free_static_uniscribe_shaper_funcs (void);
-static hb_uniscribe_shaper_funcs_t *
-hb_uniscribe_shaper_get_funcs (void)
+static struct hb_uniscribe_shaper_funcs_lazy_loader_t : hb_lazy_loader_t<hb_uniscribe_shaper_funcs_t,
+ hb_uniscribe_shaper_funcs_lazy_loader_t>
{
-retry:
- hb_uniscribe_shaper_funcs_t *funcs = uniscribe_funcs.get ();
-
- if (unlikely (!funcs))
+ static inline hb_uniscribe_shaper_funcs_t *create (void)
{
- funcs = (hb_uniscribe_shaper_funcs_t *) calloc (1, sizeof (hb_uniscribe_shaper_funcs_t));
+ hb_uniscribe_shaper_funcs_t *funcs = (hb_uniscribe_shaper_funcs_t *) calloc (1, sizeof (hb_uniscribe_shaper_funcs_t));
if (unlikely (!funcs))
return nullptr;
funcs->init ();
- if (unlikely (!uniscribe_funcs.cmpexch (nullptr, funcs)))
- {
- free (funcs);
- goto retry;
- }
-
#ifdef HB_USE_ATEXIT
- atexit (free_uniscribe_funcs); /* First person registers atexit() callback. */
+ atexit (free_static_uniscribe_shaper_funcs);
#endif
+
+ return funcs;
}
+ static inline void destroy (hb_uniscribe_shaper_funcs_t *p)
+ {
+ free ((void *) p);
+ }
+ static inline hb_uniscribe_shaper_funcs_t *get_null (void)
+ {
+ return nullptr;
+ }
+} static_uniscribe_shaper_funcs;
- return funcs;
+#ifdef HB_USE_ATEXIT
+static
+void free_static_uniscribe_shaper_funcs (void)
+{
+ static_uniscribe_shaper_funcs.free_instance ();
+}
+#endif
+
+static hb_uniscribe_shaper_funcs_t *
+hb_uniscribe_shaper_get_funcs (void)
+{
+ return static_uniscribe_shaper_funcs.get_unconst ();
}
More information about the HarfBuzz
mailing list