src/fccache.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) New commits: commit 1045a40778c1f77fd88908f7b1495c6c8f01c539 Author: Behdad Esfahbod <behdad@xxxxxxxxxx> Date: Mon Oct 15 19:35:03 2012 -0500 Make FcDirCacheDispose() threadsafe diff --git a/src/fccache.c b/src/fccache.c index 611c0de..b858d7c 100644 --- a/src/fccache.c +++ b/src/fccache.c @@ -473,7 +473,7 @@ FcCacheFindByAddr (void *object) } static void -FcCacheRemove (FcCache *cache) +FcCacheRemoveUnlocked (FcCache *cache) { FcCacheSkip **update[FC_CACHE_MAX_LEVEL]; FcCacheSkip *s, **next; @@ -482,7 +482,6 @@ FcCacheRemove (FcCache *cache) /* * Find links along each chain */ - lock_cache (); next = fcCacheChains; for (i = fcCacheMaxLevel; --i >= 0; ) { @@ -496,7 +495,6 @@ FcCacheRemove (FcCache *cache) *update[i] = s->next[i]; while (fcCacheMaxLevel > 0 && fcCacheChains[fcCacheMaxLevel - 1] == NULL) fcCacheMaxLevel--; - unlock_cache (); free (s); } @@ -520,8 +518,10 @@ FcCacheFindByStat (struct stat *cache_stat) } static void -FcDirCacheDispose (FcCache *cache) +FcDirCacheDisposeUnlocked (FcCache *cache) { + FcCacheRemoveUnlocked (cache); + switch (cache->magic) { case FC_CACHE_MAGIC_ALLOC: free (cache); @@ -534,7 +534,6 @@ FcDirCacheDispose (FcCache *cache) #endif break; } - FcCacheRemove (cache); } void @@ -549,13 +548,16 @@ FcCacheObjectReference (void *object) void FcCacheObjectDereference (void *object) { - FcCacheSkip *skip = FcCacheFindByAddr (object); + FcCacheSkip *skip; + lock_cache (); + skip = FcCacheFindByAddrUnlocked (object); if (skip) { if (FcRefDec (&skip->ref) <= 1) - FcDirCacheDispose (skip->cache); + FcDirCacheDisposeUnlocked (skip->cache); } + unlock_cache (); } void @@ -1008,7 +1010,7 @@ FcDirCacheWrite (FcCache *cache, FcConfig *config) if (cache->size < FC_CACHE_MIN_MMAP && FcStat (cache_hashed, &cache_stat)) { lock_cache (); - if (skip = FcCacheFindByAddrUnlocked (cache)) + if ((skip = FcCacheFindByAddrUnlocked (cache))) { skip->cache_dev = cache_stat.st_dev; skip->cache_ino = cache_stat.st_ino; _______________________________________________ Fontconfig mailing list Fontconfig@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/fontconfig