diff options
author | Behdad Esfahbod <behdad@behdad.org> | 2012-10-07 14:41:38 -0400 |
---|---|---|
committer | Behdad Esfahbod <behdad@behdad.org> | 2013-01-02 00:51:00 -0600 |
commit | 64af9e1917114c789ad74dd28b3248f8c0525f45 (patch) | |
tree | 31023c299c7cdd6bfc9632e1ae103c8fbf839499 /src/fclang.c | |
parent | 814871b2aaa3a22ef711ca4656507fb69c952156 (diff) | |
download | fontconfig-64af9e1917114c789ad74dd28b3248f8c0525f45.tar.gz |
Make refcounts, patterns, charsets, strings, and FcLang thread-safe
Diffstat (limited to 'src/fclang.c')
-rw-r--r-- | src/fclang.c | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/src/fclang.c b/src/fclang.c index d1fadf5..8e9b094 100644 --- a/src/fclang.c +++ b/src/fclang.c @@ -22,10 +22,11 @@ * PERFORMANCE OF THIS SOFTWARE. */ -#include <string.h> #include "fcint.h" #include "fcftint.h" +/* Objects MT-safe for readonly access. */ + typedef struct { const FcChar8 lang[8]; const FcCharSet charset; @@ -702,34 +703,38 @@ FcLangSetCompare (const FcLangSet *lsa, const FcLangSet *lsb) /* * Used in computing values -- mustn't allocate any storage - * XXX Not thread-safe */ FcLangSet * -FcLangSetPromote (const FcChar8 *lang) +FcLangSetPromote (const FcChar8 *lang, FcValuePromotionBuffer *vbuf) { - static FcLangSet ls; - static FcStrSet strs; - static FcChar8 *str; - int id; - - memset (ls.map, '\0', sizeof (ls.map)); - ls.map_size = NUM_LANG_SET_MAP; - ls.extra = 0; + int id; + typedef struct { + FcLangSet ls; + FcStrSet strs; + FcChar8 *str; + } FcLangSetPromotionBuffer; + FcLangSetPromotionBuffer *buf = (FcLangSetPromotionBuffer *) vbuf; + + FC_ASSERT_STATIC (sizeof (FcLangSetPromotionBuffer) <= sizeof (FcValuePromotionBuffer)); + + memset (buf->ls.map, '\0', sizeof (buf->ls.map)); + buf->ls.map_size = NUM_LANG_SET_MAP; + buf->ls.extra = 0; id = FcLangSetIndex (lang); if (id > 0) { - FcLangSetBitSet (&ls, id); + FcLangSetBitSet (&buf->ls, id); } else { - ls.extra = &strs; - strs.num = 1; - strs.size = 1; - strs.strs = &str; - strs.ref = 1; - str = (FcChar8 *) lang; + buf->ls.extra = &buf->strs; + buf->strs.num = 1; + buf->strs.size = 1; + buf->strs.strs = &buf->str; + FcRefInit (&buf->strs.ref, 1); + buf->str = (FcChar8 *) lang; } - return &ls; + return &buf->ls; } FcChar32 |