[Fontconfig] fontconfig: Branch 'wip/threadsafe'
Behdad Esfahbod
behdad at kemper.freedesktop.org
Mon Oct 8 09:49:59 PDT 2012
src/fcatomic.h | 1 +
src/fccache.c | 15 +++++++--------
2 files changed, 8 insertions(+), 8 deletions(-)
New commits:
commit e7876691ba90641bf38e80b958494eabc8657e23
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 7 21:03:58 2012 -0400
Make cache refcounting threadsafe
diff --git a/src/fcatomic.h b/src/fcatomic.h
index c066d12..71c0491 100644
--- a/src/fcatomic.h
+++ b/src/fcatomic.h
@@ -117,6 +117,7 @@ typedef struct _FcRef { fc_atomic_int_t count; } FcRef;
static inline void FcRefInit (FcRef *r, int v) { r->count = v; }
static inline int FcRefInc (FcRef *r) { return fc_atomic_int_add (r->count, +1); }
static inline int FcRefDec (FcRef *r) { return fc_atomic_int_add (r->count, -1); }
+static inline int FcRefAdd (FcRef *r, int v) { return fc_atomic_int_add (r->count, v); }
static inline void FcRefSetConst (FcRef *r) { r->count = FC_REF_CONSTANT_VALUE; }
static inline FcBool FcRefIsConst (const FcRef *r) { return r->count == FC_REF_CONSTANT_VALUE; }
diff --git a/src/fccache.c b/src/fccache.c
index bf50f56..91d290a 100644
--- a/src/fccache.c
+++ b/src/fccache.c
@@ -65,7 +65,7 @@ FcCacheIsMmapSafe (int fd)
} status;
static void *static_status;
- status = (int) fc_atomic_ptr_get (&static_status);
+ status = (intptr_t) fc_atomic_ptr_get (&static_status);
if (status == MMAP_NOT_INITIALIZED)
{
@@ -231,7 +231,7 @@ typedef struct _FcCacheSkip FcCacheSkip;
struct _FcCacheSkip {
FcCache *cache;
- int ref;
+ FcRef ref;
intptr_t size;
dev_t cache_dev;
ino_t cache_ino;
@@ -366,7 +366,7 @@ FcCacheInsert (FcCache *cache, struct stat *cache_stat)
s->cache = cache;
s->size = cache->size;
- s->ref = 1;
+ FcRefInit (&s->ref, 1);
if (cache_stat)
{
s->cache_dev = cache_stat->st_dev;
@@ -449,7 +449,7 @@ FcCacheFindByStat (struct stat *cache_stat)
s->cache_ino == cache_stat->st_ino &&
s->cache_mtime == cache_stat->st_mtime)
{
- s->ref++;
+ FcRefInc (&s->ref);
return s->cache;
}
return NULL;
@@ -479,7 +479,7 @@ FcCacheObjectReference (void *object)
FcCacheSkip *skip = FcCacheFindByAddr (object);
if (skip)
- skip->ref++;
+ FcRefInc (&skip->ref);
}
void
@@ -489,8 +489,7 @@ FcCacheObjectDereference (void *object)
if (skip)
{
- skip->ref--;
- if (skip->ref <= 0)
+ if (FcRefDec (&skip->ref) <= 1)
FcDirCacheDispose (skip->cache);
}
}
@@ -616,7 +615,7 @@ FcDirCacheReference (FcCache *cache, int nref)
FcCacheSkip *skip = FcCacheFindByAddr (cache);
if (skip)
- skip->ref += nref;
+ FcRefAdd (&skip->ref, nref);
}
void
More information about the Fontconfig
mailing list