Mesa (master): util: add a disk_cache_remove() function

Timothy Arceri tarceri at kemper.freedesktop.org
Thu Feb 9 01:23:13 UTC 2017


Module: Mesa
Branch: master
Commit: 4026b45bbc4c2c067feeee181c54e2beaa1cc5e0
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=4026b45bbc4c2c067feeee181c54e2beaa1cc5e0

Author: Timothy Arceri <timothy.arceri at collabora.com>
Date:   Tue Apr 26 14:56:22 2016 +1000

util: add a disk_cache_remove() function

This will be used to remove cache items created with old versions
of Mesa or other invalid cache items from the cache.

V2: rename stub function (cache_* funtions were renamed disk_cache_*)
in master.

Reviewed-by: Anuj Phogat <anuj.phogat at gmail.com>

---

 src/util/disk_cache.c | 22 ++++++++++++++++++++++
 src/util/disk_cache.h | 12 ++++++++++++
 2 files changed, 34 insertions(+)

diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c
index 551ceeb..7451b08 100644
--- a/src/util/disk_cache.c
+++ b/src/util/disk_cache.c
@@ -538,6 +538,28 @@ evict_random_item(struct disk_cache *cache)
 }
 
 void
+disk_cache_remove(struct disk_cache *cache, cache_key key)
+{
+   struct stat sb;
+
+   char *filename = get_cache_file(cache, key);
+   if (filename == NULL) {
+      return;
+   }
+
+   if (stat(filename, &sb) == -1) {
+      ralloc_free(filename);
+      return;
+   }
+
+   unlink(filename);
+   ralloc_free(filename);
+
+   if (sb.st_size)
+      p_atomic_add(cache->size, - sb.st_size);
+}
+
+void
 disk_cache_put(struct disk_cache *cache,
           cache_key key,
           const void *data,
diff --git a/src/util/disk_cache.h b/src/util/disk_cache.h
index 7e9cb80..1f2bf3d 100644
--- a/src/util/disk_cache.h
+++ b/src/util/disk_cache.h
@@ -78,6 +78,12 @@ void
 disk_cache_destroy(struct disk_cache *cache);
 
 /**
+ * Remove the item in the cache under the name \key.
+ */
+void
+disk_cache_remove(struct disk_cache *cache, cache_key key);
+
+/**
  * Store an item in the cache under the name \key.
  *
  * The item can be retrieved later with disk_cache_get(), (unless the item has
@@ -151,6 +157,12 @@ disk_cache_put(struct disk_cache *cache, cache_key key,
    return;
 }
 
+static inline void
+disk_cache_remove(struct program_cache *cache, cache_key key)
+{
+   return;
+}
+
 static inline uint8_t *
 disk_cache_get(struct disk_cache *cache, cache_key key, size_t *size)
 {




More information about the mesa-commit mailing list