Make fcobjs.c thread-safe
With this, the library should be threadsafe as far as my analysis goes!
This commit is contained in:
parent
2ae07bbcd2
commit
b604f10c0c
18
src/fcobjs.c
18
src/fcobjs.c
|
@ -40,8 +40,8 @@ _FcObjectLookupOtherTypeByName (const char *str, FcObject *id)
|
||||||
{
|
{
|
||||||
struct FcObjectOtherTypeInfo *ots, *ot;
|
struct FcObjectOtherTypeInfo *ots, *ot;
|
||||||
|
|
||||||
/* XXX MT-unsafe */
|
retry:
|
||||||
ots = other_types;
|
ots = fc_atomic_ptr_get (&other_types);
|
||||||
|
|
||||||
for (ot = ots; ot; ot = ot->next)
|
for (ot = ots; ot; ot = ot->next)
|
||||||
if (0 == strcmp (ot->object.object, str))
|
if (0 == strcmp (ot->object.object, str))
|
||||||
|
@ -55,10 +55,13 @@ _FcObjectLookupOtherTypeByName (const char *str, FcObject *id)
|
||||||
|
|
||||||
ot->object.object = strdup (str);
|
ot->object.object = strdup (str);
|
||||||
ot->object.type = -1;
|
ot->object.type = -1;
|
||||||
ot->id = next_id++; /* MT_unsafe */
|
ot->id = fc_atomic_int_add (next_id, +1);
|
||||||
ot->next = ot;
|
ot->next = ot;
|
||||||
|
|
||||||
other_types = ot;
|
if (!fc_atomic_ptr_cmpexch (&other_types, ots, ot)) {
|
||||||
|
free (ot);
|
||||||
|
goto retry;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id)
|
if (id)
|
||||||
|
@ -95,10 +98,9 @@ FcObjectLookupIdByName (const char *str)
|
||||||
const char *
|
const char *
|
||||||
FcObjectLookupOtherNameById (FcObject id)
|
FcObjectLookupOtherNameById (FcObject id)
|
||||||
{
|
{
|
||||||
/* XXX MT-unsafe */
|
|
||||||
struct FcObjectOtherTypeInfo *ot;
|
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)
|
if (ot->id == id)
|
||||||
return ot->object.object;
|
return ot->object.object;
|
||||||
|
|
||||||
|
@ -114,10 +116,9 @@ FcObjectLookupOtherTypeByName (const char *str)
|
||||||
FcPrivate const FcObjectType *
|
FcPrivate const FcObjectType *
|
||||||
FcObjectLookupOtherTypeById (FcObject id)
|
FcObjectLookupOtherTypeById (FcObject id)
|
||||||
{
|
{
|
||||||
/* XXX MT-unsafe */
|
|
||||||
struct FcObjectOtherTypeInfo *ot;
|
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)
|
if (ot->id == id)
|
||||||
return &ot->object;
|
return &ot->object;
|
||||||
|
|
||||||
|
@ -125,6 +126,5 @@ FcObjectLookupOtherTypeById (FcObject id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define __fcobjs__
|
|
||||||
#include "fcaliastail.h"
|
#include "fcaliastail.h"
|
||||||
#undef __fcobjs__
|
#undef __fcobjs__
|
||||||
|
|
Loading…
Reference in New Issue