From 8d450dd188dea2d63a03f74d903a76741de8a217 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 11 Oct 2017 12:43:46 +0200 Subject: [PATCH] Infrastructure for creating CTFont with correct font size https://github.com/behdad/harfbuzz/issues/360 --- src/hb-shaper-private.hh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/hb-shaper-private.hh b/src/hb-shaper-private.hh index 381398a61..2481ef8ac 100644 --- a/src/hb-shaper-private.hh +++ b/src/hb-shaper-private.hh @@ -88,11 +88,23 @@ struct hb_shaper_data_t { HB_SHAPER_DATA_DESTROY_FUNC (shaper, object) (data); #define HB_SHAPER_DATA_ENSURE_DEFINE(shaper, object) \ + HB_SHAPER_DATA_ENSURE_DEFINE_WITH_CONDITION(shaper, object, true) + +#define HB_SHAPER_DATA_ENSURE_DEFINE_WITH_CONDITION(shaper, object, condition) \ bool \ HB_SHAPER_DATA_ENSURE_FUNC(shaper, object) (hb_##object##_t *object) \ {\ retry: \ HB_SHAPER_DATA_TYPE (shaper, object) *data = (HB_SHAPER_DATA_TYPE (shaper, object) *) hb_atomic_ptr_get (&HB_SHAPER_DATA (shaper, object)); \ + if (likely (data) && !(condition)) { \ + /* Drop and recreate. */ \ + /* If someone dropped it in the mean time, throw it away and don't touch it. \ + * Otherwise, destruct it. */ \ + if (hb_atomic_ptr_cmpexch (&HB_SHAPER_DATA (shaper, object), data, NULL)) { \ + HB_SHAPER_DATA_DESTROY_FUNC (shaper, object) (data); \ + } \ + goto retry; \ + } \ if (unlikely (!data)) { \ data = HB_SHAPER_DATA_CREATE_FUNC (shaper, object) (object); \ if (unlikely (!data)) \