]> git.wh0rd.org Git - fontconfig.git/commitdiff
[cache] After writing cache to file, update the internal copy to reflect this
authorBehdad Esfahbod <behdad@behdad.org>
Thu, 5 Feb 2009 07:46:16 +0000 (02:46 -0500)
committerBehdad Esfahbod <behdad@behdad.org>
Sun, 15 Feb 2009 21:40:25 +0000 (13:40 -0800)
Only do it for small caches though.  For large cache we'd better off loading
the cache file again, mmap()ing it.

Based on patch from Diego Santa Cruz.

src/fccache.c

index f35304a40cde1636a5b6d785c13593e13df227a6..ba28ddc6ab3ca14f96d4660b75da3cb4c4bda9bf 100644 (file)
@@ -844,6 +844,8 @@ FcDirCacheWrite (FcCache *cache, FcConfig *config)
     FcStrList      *list;
     FcChar8        *cache_dir = NULL;
     FcChar8        *test_dir;
+    FcCacheSkip     *skip;
+    struct stat     cache_stat;
     int                    magic;
     int                    written;
 
@@ -929,6 +931,20 @@ FcDirCacheWrite (FcCache *cache, FcConfig *config)
     close(fd);
     if (!FcAtomicReplaceOrig(atomic))
         goto bail4;
+
+    /* If the file is small, update the cache chain entry such that the
+     * new cache file is not read again.  If it's large, we don't do that
+     * such that we reload it, using mmap, which is shared across processes.
+     */
+    if (cache->size < FC_CACHE_MIN_MMAP &&
+       (skip = FcCacheFindByAddr (cache)) &&
+       FcStat (cache_hashed, &cache_stat))
+    {
+       skip->cache_dev = cache_stat.st_dev;
+       skip->cache_ino = cache_stat.st_ino;
+       skip->cache_mtime = cache_stat.st_mtime;
+    }
+
     FcStrFree (cache_hashed);
     FcAtomicUnlock (atomic);
     FcAtomicDestroy (atomic);