Make FcCacheIsMmapSafe() threadsafe
This commit is contained in:
parent
b27a22aae9
commit
b8f238e49d
|
@ -59,26 +59,32 @@ static void MD5Transform(FcChar32 buf[4], FcChar32 in[16]);
|
||||||
static FcBool
|
static FcBool
|
||||||
FcCacheIsMmapSafe (int fd)
|
FcCacheIsMmapSafe (int fd)
|
||||||
{
|
{
|
||||||
static FcBool is_initialized = FcFalse;
|
enum {
|
||||||
static FcBool is_env_available = FcFalse;
|
MMAP_NOT_INITIALIZED = 0,
|
||||||
static FcBool use_mmap = FcFalse;
|
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;
|
const char *env = getenv ("FONTCONFIG_USE_MMAP");
|
||||||
|
FcBool use;
|
||||||
env = getenv ("FONTCONFIG_USE_MMAP");
|
if (env && FcNameBool ((const FcChar8 *) env, &use))
|
||||||
if (env)
|
status = use ? MMAP_USE : MMAP_DONT_USE;
|
||||||
{
|
else
|
||||||
if (FcNameBool ((const FcChar8 *)env, &use_mmap))
|
status = MMAP_CHECK_FS;
|
||||||
is_env_available = FcTrue;
|
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);
|
return FcIsFsMmapSafe (fd);
|
||||||
|
else
|
||||||
|
return status == MMAP_USE;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char bin2hex[] = { '0', '1', '2', '3',
|
static const char bin2hex[] = { '0', '1', '2', '3',
|
||||||
|
|
Loading…
Reference in New Issue