Make FcDirCacheDispose() threadsafe

This commit is contained in:
Behdad Esfahbod 2012-10-15 19:35:03 -05:00
parent 68b8ae9af8
commit 2ae07bbcd2
1 changed files with 9 additions and 7 deletions

View File

@ -475,7 +475,7 @@ FcCacheFindByAddr (void *object)
} }
static void static void
FcCacheRemove (FcCache *cache) FcCacheRemoveUnlocked (FcCache *cache)
{ {
FcCacheSkip **update[FC_CACHE_MAX_LEVEL]; FcCacheSkip **update[FC_CACHE_MAX_LEVEL];
FcCacheSkip *s, **next; FcCacheSkip *s, **next;
@ -484,7 +484,6 @@ FcCacheRemove (FcCache *cache)
/* /*
* Find links along each chain * Find links along each chain
*/ */
lock_cache ();
next = fcCacheChains; next = fcCacheChains;
for (i = fcCacheMaxLevel; --i >= 0; ) for (i = fcCacheMaxLevel; --i >= 0; )
{ {
@ -498,7 +497,6 @@ FcCacheRemove (FcCache *cache)
*update[i] = s->next[i]; *update[i] = s->next[i];
while (fcCacheMaxLevel > 0 && fcCacheChains[fcCacheMaxLevel - 1] == NULL) while (fcCacheMaxLevel > 0 && fcCacheChains[fcCacheMaxLevel - 1] == NULL)
fcCacheMaxLevel--; fcCacheMaxLevel--;
unlock_cache ();
free (s); free (s);
} }
@ -522,8 +520,10 @@ FcCacheFindByStat (struct stat *cache_stat)
} }
static void static void
FcDirCacheDispose (FcCache *cache) FcDirCacheDisposeUnlocked (FcCache *cache)
{ {
FcCacheRemoveUnlocked (cache);
switch (cache->magic) { switch (cache->magic) {
case FC_CACHE_MAGIC_ALLOC: case FC_CACHE_MAGIC_ALLOC:
free (cache); free (cache);
@ -536,7 +536,6 @@ FcDirCacheDispose (FcCache *cache)
#endif #endif
break; break;
} }
FcCacheRemove (cache);
} }
void void
@ -551,13 +550,16 @@ FcCacheObjectReference (void *object)
void void
FcCacheObjectDereference (void *object) FcCacheObjectDereference (void *object)
{ {
FcCacheSkip *skip = FcCacheFindByAddr (object); FcCacheSkip *skip;
lock_cache ();
skip = FcCacheFindByAddrUnlocked (object);
if (skip) if (skip)
{ {
if (FcRefDec (&skip->ref) <= 1) if (FcRefDec (&skip->ref) <= 1)
FcDirCacheDispose (skip->cache); FcDirCacheDisposeUnlocked (skip->cache);
} }
unlock_cache ();
} }
void void