/* * Enables or disables the cache. Note that the cache is read-only, changes to * the working directory are NOT reflected in the cache while enabled. */ int fscache_enable(int enable) { int result; if (!initialized) { /* allow the cache to be disabled entirely */ if (!core_fscache) return 0; InitializeCriticalSection(&mutex); hashmap_init(&map, (hashmap_cmp_fn) fsentry_cmp, NULL, 0); initialized = 1; } result = enable ? InterlockedIncrement(&enabled) : InterlockedDecrement(&enabled); if (enable && result == 1) { /* redirect opendir and lstat to the fscache implementations */ opendir = fscache_opendir; lstat = fscache_lstat; } else if (!enable && !result) { /* reset opendir and lstat to the original implementations */ opendir = dirent_opendir; lstat = mingw_lstat; EnterCriticalSection(&mutex); fscache_clear(); LeaveCriticalSection(&mutex); } trace_printf_key(&trace_fscache, "fscache: enable(%d)\n", enable); return result; }
/* * Flush cached stats result when fscache is enabled. */ void fscache_flush(void) { struct fscache *cache = fscache_getcache(); if (cache && cache->enabled) { fscache_clear(cache); } }
/* * Flush cached stats result when fscache is enabled. */ void fscache_flush(void) { if (enabled) { EnterCriticalSection(&mutex); fscache_clear(); LeaveCriticalSection(&mutex); } }