Add a big cache lock

Not used yet.
This commit is contained in:
Behdad Esfahbod 2012-10-08 20:02:05 -04:00
parent 8d2bbb193a
commit 91dd7d28ff
1 changed files with 41 additions and 0 deletions

View File

@ -307,6 +307,45 @@ FcRandom(void)
return result; return result;
} }
static FcMutex *cache_lock;
static void
lock_cache (void)
{
FcMutex *lock;
retry:
lock = fc_atomic_ptr_get (&cache_lock);
if (!lock) {
lock = (FcMutex *) malloc (sizeof (FcMutex));
FcMutexInit (lock);
if (!fc_atomic_ptr_cmpexch (&cache_lock, NULL, lock)) {
FcMutexFinish (lock);
goto retry;
}
}
FcMutexLock (lock);
}
static void
unlock_cache (void)
{
FcMutexUnlock (cache_lock);
}
static void
free_lock (void)
{
FcMutex *lock;
lock = fc_atomic_ptr_get (&cache_lock);
if (lock && fc_atomic_ptr_cmpexch (&cache_lock, lock, NULL)) {
FcMutexFinish (lock);
free (lock);
}
}
/* /*
* Generate a random level number, distributed * Generate a random level number, distributed
* so that each level is 1/4 as likely as the one before * so that each level is 1/4 as likely as the one before
@ -504,6 +543,8 @@ FcCacheFini (void)
for (i = 0; i < FC_CACHE_MAX_LEVEL; i++) for (i = 0; i < FC_CACHE_MAX_LEVEL; i++)
assert (fcCacheChains[i] == NULL); assert (fcCacheChains[i] == NULL);
assert (fcCacheMaxLevel == 0); assert (fcCacheMaxLevel == 0);
free_lock ();
} }
static FcBool static FcBool