summaryrefslogtreecommitdiff
path: root/src/hb-shaper.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/hb-shaper.cc')
-rw-r--r--src/hb-shaper.cc15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/hb-shaper.cc b/src/hb-shaper.cc
index b25566d..d44d8c9 100644
--- a/src/hb-shaper.cc
+++ b/src/hb-shaper.cc
@@ -44,8 +44,13 @@ static const hb_shaper_pair_t *static_shapers;
static
void free_static_shapers (void)
{
- if (unlikely (static_shapers != all_shapers))
- free ((void *) static_shapers);
+retry:
+ hb_shaper_pair_t *shapers = (hb_shaper_pair_t *) hb_atomic_ptr_get (&static_shapers);
+ if (!hb_atomic_ptr_cmpexch (&static_shapers, shapers, nullptr))
+ goto retry;
+
+ if (unlikely (shapers != all_shapers))
+ free ((void *) shapers);
}
#endif
@@ -59,14 +64,14 @@ retry:
{
char *env = getenv ("HB_SHAPER_LIST");
if (!env || !*env) {
- (void) hb_atomic_ptr_cmpexch (&static_shapers, NULL, &all_shapers[0]);
+ (void) hb_atomic_ptr_cmpexch (&static_shapers, nullptr, &all_shapers[0]);
return (const hb_shaper_pair_t *) all_shapers;
}
/* Not found; allocate one. */
shapers = (hb_shaper_pair_t *) calloc (1, sizeof (all_shapers));
if (unlikely (!shapers)) {
- (void) hb_atomic_ptr_cmpexch (&static_shapers, NULL, &all_shapers[0]);
+ (void) hb_atomic_ptr_cmpexch (&static_shapers, nullptr, &all_shapers[0]);
return (const hb_shaper_pair_t *) all_shapers;
}
@@ -97,7 +102,7 @@ retry:
p = end + 1;
}
- if (!hb_atomic_ptr_cmpexch (&static_shapers, NULL, shapers)) {
+ if (!hb_atomic_ptr_cmpexch (&static_shapers, nullptr, shapers)) {
free (shapers);
goto retry;
}