From: Behdad Esfahbod Date: Wed, 11 Oct 2017 10:43:46 +0000 (+0200) Subject: Infrastructure for creating CTFont with correct font size X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8d450dd188dea2d63a03f74d903a76741de8a217;p=platform%2Fupstream%2FlibHarfBuzzSharp.git Infrastructure for creating CTFont with correct font size https://github.com/behdad/harfbuzz/issues/360 --- diff --git a/src/hb-shaper-private.hh b/src/hb-shaper-private.hh index 381398a..2481ef8 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)) \