diff options
author | Behdad Esfahbod <behdad@behdad.org> | 2018-08-12 18:20:53 -0700 |
---|---|---|
committer | Behdad Esfahbod <behdad@behdad.org> | 2018-08-12 18:20:53 -0700 |
commit | 9bbd1cdf068635f4a737f1fc9ab54ba075601a5d (patch) | |
tree | 5f95f9f35aaf71b53d7fa6cb4f064f109058ac8a /src/hb-uniscribe.cc | |
parent | 266368993625e0cfb6eef9188f8b9aa29fb97391 (diff) |
[uniscribe] Use lazy loader
Fixes https://github.com/harfbuzz/harfbuzz/issues/1129
Diffstat (limited to 'src/hb-uniscribe.cc')
-rw-r--r-- | src/hb-uniscribe.cc | 56 |
1 files changed, 29 insertions, 27 deletions
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 (); } |