summaryrefslogtreecommitdiff
path: root/src/fcobjs.c
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@behdad.org>2013-01-02 01:09:20 -0600
committerBehdad Esfahbod <behdad@behdad.org>2013-01-02 01:09:43 -0600
commitb604f10c0c31a56ae16154dfe6a2f13b795aaabf (patch)
treeea4b08df82104ddfde00ffe185761c0ad4d127b5 /src/fcobjs.c
parent2ae07bbcd2a7650f2711b45e78e65e2ca1c4a17a (diff)
downloadfontconfig-b604f10c0c31a56ae16154dfe6a2f13b795aaabf.tar.gz
Make fcobjs.c thread-safe
With this, the library should be threadsafe as far as my analysis goes!
Diffstat (limited to 'src/fcobjs.c')
-rw-r--r--src/fcobjs.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/fcobjs.c b/src/fcobjs.c
index e3ba2f8..aaabb62 100644
--- a/src/fcobjs.c
+++ b/src/fcobjs.c
@@ -40,8 +40,8 @@ _FcObjectLookupOtherTypeByName (const char *str, FcObject *id)
{
struct FcObjectOtherTypeInfo *ots, *ot;
- /* XXX MT-unsafe */
- ots = other_types;
+retry:
+ ots = fc_atomic_ptr_get (&other_types);
for (ot = ots; ot; ot = ot->next)
if (0 == strcmp (ot->object.object, str))
@@ -55,10 +55,13 @@ _FcObjectLookupOtherTypeByName (const char *str, FcObject *id)
ot->object.object = strdup (str);
ot->object.type = -1;
- ot->id = next_id++; /* MT_unsafe */
+ ot->id = fc_atomic_int_add (next_id, +1);
ot->next = ot;
- other_types = ot;
+ if (!fc_atomic_ptr_cmpexch (&other_types, ots, ot)) {
+ free (ot);
+ goto retry;
+ }
}
if (id)
@@ -95,10 +98,9 @@ FcObjectLookupIdByName (const char *str)
const char *
FcObjectLookupOtherNameById (FcObject id)
{
- /* XXX MT-unsafe */
struct FcObjectOtherTypeInfo *ot;
- for (ot = other_types; ot; ot = ot->next)
+ for (ot = fc_atomic_ptr_get (&other_types); ot; ot = ot->next)
if (ot->id == id)
return ot->object.object;
@@ -114,10 +116,9 @@ FcObjectLookupOtherTypeByName (const char *str)
FcPrivate const FcObjectType *
FcObjectLookupOtherTypeById (FcObject id)
{
- /* XXX MT-unsafe */
struct FcObjectOtherTypeInfo *ot;
- for (ot = other_types; ot; ot = ot->next)
+ for (ot = fc_atomic_ptr_get (&other_types); ot; ot = ot->next)
if (ot->id == id)
return &ot->object;
@@ -125,6 +126,5 @@ FcObjectLookupOtherTypeById (FcObject id)
}
-#define __fcobjs__
#include "fcaliastail.h"
#undef __fcobjs__