Mesa (master): disk_cache: add new OS specific helper disk_cache_evict_item()
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Fri Sep 11 06:17:26 UTC 2020
Module: Mesa
Branch: master
Commit: 8598dc1a7582f82827cc08fefa89a0e73979d53a
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=8598dc1a7582f82827cc08fefa89a0e73979d53a
Author: Timothy Arceri <tarceri at itsqueeze.com>
Date: Wed Aug 5 14:46:42 2020 +1000
disk_cache: add new OS specific helper disk_cache_evict_item()
Reviewed-by: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6197>
---
src/util/disk_cache.c | 13 +------------
src/util/disk_cache_os.c | 16 ++++++++++++++++
src/util/disk_cache_os.h | 3 +++
3 files changed, 20 insertions(+), 12 deletions(-)
diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c
index 8d6817f8164..c2d5db4f588 100644
--- a/src/util/disk_cache.c
+++ b/src/util/disk_cache.c
@@ -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
diff --git a/src/util/disk_cache_os.c b/src/util/disk_cache_os.c
index 28885820bf1..d23b2f7d82f 100644
--- a/src/util/disk_cache_os.c
+++ b/src/util/disk_cache_os.c
@@ -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.
*
diff --git a/src/util/disk_cache_os.h b/src/util/disk_cache_os.h
index 04102545aa7..e753d08bd99 100644
--- a/src/util/disk_cache_os.h
+++ b/src/util/disk_cache_os.h
@@ -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);
More information about the mesa-commit
mailing list