From 5aa2c6e194bc75637d3f4862a096c0e7100072e2 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 28 Mar 2018 15:33:51 -0700 Subject: [PATCH] [atexit] Make hb_languate_item_t *langs freeing threadsafe Part of https://github.com/harfbuzz/harfbuzz/issues/923 --- src/hb-common.cc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/hb-common.cc b/src/hb-common.cc index d1fcf799a..ce3d01b8f 100644 --- a/src/hb-common.cc +++ b/src/hb-common.cc @@ -252,11 +252,16 @@ static hb_language_item_t *langs; static void free_langs (void) { - while (langs) { - hb_language_item_t *next = langs->next; - langs->finish (); - free (langs); - langs = next; +retry: + hb_language_item_t *first_lang = (hb_language_item_t *) hb_atomic_ptr_get (&langs); + if (!hb_atomic_ptr_cmpexch (&langs, first_lang, nullptr)) + goto retry; + + while (first_lang) { + hb_language_item_t *next = first_lang->next; + first_lang->finish (); + free (first_lang); + first_lang = next; } } #endif