Mesa (master): disk_cache: move get_cache_file() to an OS specific helper
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Fri Sep 11 06:17:26 UTC 2020
Module: Mesa
Branch: master
Commit: 7893dc405cd2afef11bd5a2af44ab41c5c9b2e44
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=7893dc405cd2afef11bd5a2af44ab41c5c9b2e44
Author: Timothy Arceri <tarceri at itsqueeze.com>
Date: Wed Aug 5 14:35:12 2020 +1000
disk_cache: move get_cache_file() to an OS specific helper
Reviewed-by: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6197>
---
src/util/disk_cache.c | 28 +++-------------------------
src/util/disk_cache_os.c | 22 ++++++++++++++++++++++
src/util/disk_cache_os.h | 3 +++
3 files changed, 28 insertions(+), 25 deletions(-)
diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c
index 577c7b99a77..8d6817f8164 100644
--- a/src/util/disk_cache.c
+++ b/src/util/disk_cache.c
@@ -224,34 +224,12 @@ disk_cache_wait_for_idle(struct disk_cache *cache)
util_queue_finish(&cache->cache_queue);
}
-/* Return a filename within the cache's directory corresponding to 'key'. The
- * returned filename is ralloced with 'cache' as the parent context.
- *
- * Returns NULL if out of memory.
- */
-static char *
-get_cache_file(struct disk_cache *cache, const cache_key key)
-{
- char buf[41];
- char *filename;
-
- if (cache->path_init_failed)
- return NULL;
-
- _mesa_sha1_format(buf, key);
- if (asprintf(&filename, "%s/%c%c/%s", cache->path, buf[0],
- buf[1], buf + 2) == -1)
- return NULL;
-
- return filename;
-}
-
void
disk_cache_remove(struct disk_cache *cache, const cache_key key)
{
struct stat sb;
- char *filename = get_cache_file(cache, key);
+ char *filename = disk_cache_get_cache_filename(cache, key);
if (filename == NULL) {
return;
}
@@ -348,7 +326,7 @@ cache_put(void *job, int thread_index)
char *filename = NULL;
struct disk_cache_put_job *dc_job = (struct disk_cache_put_job *) job;
- filename = get_cache_file(dc_job->cache, dc_job->key);
+ filename = disk_cache_get_cache_filename(dc_job->cache, dc_job->key);
if (filename == NULL)
goto done;
@@ -474,7 +452,7 @@ disk_cache_get(struct disk_cache *cache, const cache_key key, size_t *size)
return blob;
}
- filename = get_cache_file(cache, key);
+ filename = disk_cache_get_cache_filename(cache, key);
if (filename == NULL)
goto fail;
diff --git a/src/util/disk_cache_os.c b/src/util/disk_cache_os.c
index a6c7504f08e..28885820bf1 100644
--- a/src/util/disk_cache_os.c
+++ b/src/util/disk_cache_os.c
@@ -438,6 +438,28 @@ disk_cache_evict_lru_item(struct disk_cache *cache)
p_atomic_add(cache->size, - (uint64_t)size);
}
+/* Return a filename within the cache's directory corresponding to 'key'. The
+ * returned filename is ralloced with 'cache' as the parent context.
+ *
+ * Returns NULL if out of memory.
+ */
+char *
+disk_cache_get_cache_filename(struct disk_cache *cache, const cache_key key)
+{
+ char buf[41];
+ char *filename;
+
+ if (cache->path_init_failed)
+ return NULL;
+
+ _mesa_sha1_format(buf, key);
+ if (asprintf(&filename, "%s/%c%c/%s", cache->path, buf[0],
+ buf[1], buf + 2) == -1)
+ return NULL;
+
+ return filename;
+}
+
void
disk_cache_write_item_to_disk(struct disk_cache_put_job *dc_job,
struct cache_entry_file_data *cf_data,
diff --git a/src/util/disk_cache_os.h b/src/util/disk_cache_os.h
index da5b6a306f8..04102545aa7 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);
+char *
+disk_cache_get_cache_filename(struct disk_cache *cache, const cache_key key);
+
void
disk_cache_write_item_to_disk(struct disk_cache_put_job *dc_job,
struct cache_entry_file_data *cf_data,
More information about the mesa-commit
mailing list