Make FcCacheIsMmapSafe() threadsafe

This commit is contained in:
Behdad Esfahbod 2012-10-07 17:42:18 -04:00
parent b27a22aae9
commit b8f238e49d
1 changed files with 22 additions and 16 deletions

View File

@ -59,26 +59,32 @@ static void MD5Transform(FcChar32 buf[4], FcChar32 in[16]);
static FcBool
FcCacheIsMmapSafe (int fd)
{
static FcBool is_initialized = FcFalse;
static FcBool is_env_available = FcFalse;
static FcBool use_mmap = FcFalse;
enum {
MMAP_NOT_INITIALIZED = 0,
MMAP_USE,
MMAP_DONT_USE,
MMAP_CHECK_FS,
} status;
static void *static_status;
if (!is_initialized)
status = (intptr_t) fc_atomic_ptr_get (&static_status);
if (status == MMAP_NOT_INITIALIZED)
{
const char *env;
env = getenv ("FONTCONFIG_USE_MMAP");
if (env)
{
if (FcNameBool ((const FcChar8 *)env, &use_mmap))
is_env_available = FcTrue;
const char *env = getenv ("FONTCONFIG_USE_MMAP");
FcBool use;
if (env && FcNameBool ((const FcChar8 *) env, &use))
status = use ? MMAP_USE : MMAP_DONT_USE;
else
status = MMAP_CHECK_FS;
fc_atomic_ptr_cmpexch (&static_status, NULL, (void *) status);
}
is_initialized = FcTrue;
}
if (is_env_available)
return use_mmap;
if (status == MMAP_CHECK_FS)
return FcIsFsMmapSafe (fd);
else
return status == MMAP_USE;
}
static const char bin2hex[] = { '0', '1', '2', '3',