[Mesa-dev] [PATCH 47/65] glsl: add a cache_remove() function

Timothy Arceri timothy.arceri at collabora.com
Fri Apr 29 13:33:46 UTC 2016


This will be used to remove cache items created with an old version
of Mesa from the cache.
---
 src/compiler/glsl/cache.c | 22 ++++++++++++++++++++++
 src/compiler/glsl/cache.h |  6 ++++++
 2 files changed, 28 insertions(+)

diff --git a/src/compiler/glsl/cache.c b/src/compiler/glsl/cache.c
index 22c4ee1..a6a9e47 100644
--- a/src/compiler/glsl/cache.c
+++ b/src/compiler/glsl/cache.c
@@ -537,6 +537,28 @@ evict_random_item(struct program_cache *cache)
 }
 
 void
+cache_remove(struct program_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
 cache_put(struct program_cache *cache,
           cache_key key,
           const void *data,
diff --git a/src/compiler/glsl/cache.h b/src/compiler/glsl/cache.h
index 78df32b..4878a78 100644
--- a/src/compiler/glsl/cache.h
+++ b/src/compiler/glsl/cache.h
@@ -77,6 +77,12 @@ void
 cache_destroy(struct program_cache *cache);
 
 /**
+ * Remove the item in the cache under the name \key.
+ */
+void
+cache_remove(struct program_cache *cache, cache_key key);
+
+/**
  * Store an item in the cache under the name \key.
  *
  * The item can be retrieved later with cache_get(), (unless the item has
-- 
2.5.5



More information about the mesa-dev mailing list