disk_cache: add new OS specific helper disk_cache_evict_item()

Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6197>
This commit is contained in:
Timothy Arceri 2020-08-05 14:46:42 +10:00 committed by Marge Bot
parent 7893dc405c
commit 8598dc1a75
3 changed files with 20 additions and 12 deletions

View File

@ -227,23 +227,12 @@ disk_cache_wait_for_idle(struct disk_cache *cache)
void
disk_cache_remove(struct disk_cache *cache, const cache_key key)
{
struct stat sb;
char *filename = disk_cache_get_cache_filename(cache, key);
if (filename == NULL) {
return;
}
if (stat(filename, &sb) == -1) {
free(filename);
return;
}
unlink(filename);
free(filename);
if (sb.st_blocks)
p_atomic_add(cache->size, - (uint64_t)sb.st_blocks * 512);
disk_cache_evict_item(cache, filename);
}
static ssize_t

View File

@ -438,6 +438,22 @@ disk_cache_evict_lru_item(struct disk_cache *cache)
p_atomic_add(cache->size, - (uint64_t)size);
}
void
disk_cache_evict_item(struct disk_cache *cache, char *filename)
{
struct stat sb;
if (stat(filename, &sb) == -1) {
free(filename);
return;
}
unlink(filename);
free(filename);
if (sb.st_blocks)
p_atomic_add(cache->size, - (uint64_t)sb.st_blocks * 512);
}
/* Return a filename within the cache's directory corresponding to 'key'. The
* returned filename is ralloced with 'cache' as the parent context.
*

View File

@ -100,6 +100,9 @@ disk_cache_generate_cache_dir(void *mem_ctx);
void
disk_cache_evict_lru_item(struct disk_cache *cache);
void
disk_cache_evict_item(struct disk_cache *cache, char *filename);
char *
disk_cache_get_cache_filename(struct disk_cache *cache, const cache_key key);