[graphite] Make get_table threadsafe (#931)
diff --git a/src/hb-graphite2.cc b/src/hb-graphite2.cc
index 46fe139..5d95ca5 100644
--- a/src/hb-graphite2.cc
+++ b/src/hb-graphite2.cc
@@ -79,10 +79,12 @@
p->blob = blob;
p->tag = tag;
- /* TODO Not thread-safe, but fairly harmless.
- * We can do the double-checked pointer cmpexch thing here. */
- p->next = face_data->tlist;
- face_data->tlist = p;
+retry:
+ hb_graphite2_tablelist_t *tlist = (hb_graphite2_tablelist_t *) hb_atomic_ptr_get (&face_data->tlist);
+ p->next = tlist;
+
+ if (!hb_atomic_ptr_cmpexch (&face_data->tlist, tlist, p))
+ goto retry;
}
unsigned int tlen;
diff --git a/src/hb-graphite2.h b/src/hb-graphite2.h
index 82b1e64..05c55de 100644
--- a/src/hb-graphite2.h
+++ b/src/hb-graphite2.h
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2011 Martin Hosken
- * Copyright (C) 2011 SIL International
+ * Copyright © 2011 Martin Hosken
+ * Copyright © 2011 SIL International
*
* This is part of HarfBuzz, a text shaping library.
*