util/disk_cache: Use os independent functions instead of getenv
In preparation to allow disk cache to work on Android. Signed-off-by: Danylo Piliaiev <dpiliaiev@igalia.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36821>
This commit is contained in:
committed by
Marge Bot
parent
1184830f60
commit
d93813c7a0
@@ -122,8 +122,8 @@ disk_cache_type_create(const char *gpu_name,
|
||||
if (!disk_cache_enabled())
|
||||
goto path_fail;
|
||||
|
||||
char *path = disk_cache_generate_cache_dir(local, gpu_name, driver_id,
|
||||
cache_dir_name, cache_type, true);
|
||||
const char *path =
|
||||
disk_cache_generate_cache_dir(local, gpu_name, driver_id, cache_dir_name, cache_type, true);
|
||||
if (!path)
|
||||
goto path_fail;
|
||||
|
||||
@@ -146,7 +146,7 @@ disk_cache_type_create(const char *gpu_name,
|
||||
goto path_fail;
|
||||
}
|
||||
|
||||
if (!getenv("MESA_SHADER_CACHE_DIR") && !getenv("MESA_GLSL_CACHE_DIR"))
|
||||
if (!os_get_option("MESA_SHADER_CACHE_DIR") && !os_get_option("MESA_GLSL_CACHE_DIR"))
|
||||
disk_cache_touch_cache_user_marker(cache->path);
|
||||
|
||||
cache->type = cache_type;
|
||||
@@ -154,7 +154,7 @@ disk_cache_type_create(const char *gpu_name,
|
||||
cache->stats.enabled = debug_get_bool_option("MESA_SHADER_CACHE_SHOW_STATS",
|
||||
false);
|
||||
|
||||
if (!disk_cache_mmap_cache_index(local, cache, path))
|
||||
if (!disk_cache_mmap_cache_index(local, cache))
|
||||
goto path_fail;
|
||||
|
||||
cache->max_size = max_size;
|
||||
@@ -221,7 +221,7 @@ disk_cache_create(const char *gpu_name, const char *driver_id,
|
||||
enum disk_cache_type cache_type;
|
||||
struct disk_cache *cache;
|
||||
uint64_t max_size = 0;
|
||||
char *max_size_str;
|
||||
const char *max_size_str;
|
||||
|
||||
if (debug_get_bool_option("MESA_DISK_CACHE_SINGLE_FILE", false)) {
|
||||
cache_type = DISK_CACHE_SINGLE_FILE;
|
||||
@@ -230,7 +230,8 @@ disk_cache_create(const char *gpu_name, const char *driver_id,
|
||||
/* Since switching the default cache to <mesa_shader_cache_db>, remove the
|
||||
* old cache folder if it hasn't been modified for more than 7 days.
|
||||
*/
|
||||
if (!getenv("MESA_SHADER_CACHE_DIR") && !getenv("MESA_GLSL_CACHE_DIR") && disk_cache_enabled())
|
||||
if (!os_get_option("MESA_SHADER_CACHE_DIR") && !os_get_option("MESA_GLSL_CACHE_DIR") &&
|
||||
disk_cache_enabled())
|
||||
disk_cache_delete_old_cache();
|
||||
} else if (debug_get_bool_option("MESA_DISK_CACHE_MULTI_FILE", true)) {
|
||||
cache_type = DISK_CACHE_MULTI_FILE;
|
||||
@@ -238,10 +239,10 @@ disk_cache_create(const char *gpu_name, const char *driver_id,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
max_size_str = getenv("MESA_SHADER_CACHE_MAX_SIZE");
|
||||
max_size_str = os_get_option("MESA_SHADER_CACHE_MAX_SIZE");
|
||||
|
||||
if (!max_size_str) {
|
||||
max_size_str = getenv("MESA_GLSL_CACHE_MAX_SIZE");
|
||||
max_size_str = os_get_option("MESA_GLSL_CACHE_MAX_SIZE");
|
||||
if (max_size_str)
|
||||
fprintf(stderr,
|
||||
"*** MESA_GLSL_CACHE_MAX_SIZE is deprecated; "
|
||||
|
||||
@@ -893,7 +893,7 @@ disk_cache_write_item_to_disk(struct disk_cache_put_job *dc_job,
|
||||
* If the mkdir param is set we create the directory if it doesn't already
|
||||
* exist, if it does not exist and the param is false NULL will be returned.
|
||||
*/
|
||||
char *
|
||||
const char *
|
||||
disk_cache_generate_cache_dir(void *mem_ctx, const char *gpu_name,
|
||||
const char *driver_id,
|
||||
const char *cache_dir_name_custom,
|
||||
@@ -913,10 +913,10 @@ disk_cache_generate_cache_dir(void *mem_ctx, const char *gpu_name,
|
||||
cache_dir_name = CACHE_DIR_NAME_DB;
|
||||
}
|
||||
|
||||
char *path = secure_getenv("MESA_SHADER_CACHE_DIR");
|
||||
const char *path = os_get_option_secure("MESA_SHADER_CACHE_DIR");
|
||||
|
||||
if (!path) {
|
||||
path = secure_getenv("MESA_GLSL_CACHE_DIR");
|
||||
path = os_get_option_secure("MESA_GLSL_CACHE_DIR");
|
||||
if (path)
|
||||
fprintf(stderr,
|
||||
"*** MESA_GLSL_CACHE_DIR is deprecated; "
|
||||
@@ -1102,13 +1102,12 @@ disk_cache_touch_cache_user_marker(char *path)
|
||||
}
|
||||
|
||||
bool
|
||||
disk_cache_mmap_cache_index(void *mem_ctx, struct disk_cache *cache,
|
||||
char *path)
|
||||
disk_cache_mmap_cache_index(void *mem_ctx, struct disk_cache *cache)
|
||||
{
|
||||
int fd = -1;
|
||||
bool mapped = false;
|
||||
|
||||
path = ralloc_asprintf(mem_ctx, "%s/index", cache->path);
|
||||
char *path = ralloc_asprintf(mem_ctx, "%s/index", cache->path);
|
||||
if (path == NULL)
|
||||
goto path_fail;
|
||||
|
||||
@@ -1256,8 +1255,8 @@ void
|
||||
disk_cache_delete_old_cache(void)
|
||||
{
|
||||
void *ctx = ralloc_context(NULL);
|
||||
char *dirname = disk_cache_generate_cache_dir(ctx, NULL, NULL, NULL,
|
||||
DISK_CACHE_MULTI_FILE, false);
|
||||
const char *dirname = disk_cache_generate_cache_dir(ctx, NULL, NULL, NULL,
|
||||
DISK_CACHE_MULTI_FILE, false);
|
||||
if (!dirname)
|
||||
goto finish;
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ struct disk_cache_put_job {
|
||||
struct cache_item_metadata cache_item_metadata;
|
||||
};
|
||||
|
||||
char *
|
||||
const char *
|
||||
disk_cache_generate_cache_dir(void *mem_ctx, const char *gpu_name,
|
||||
const char *driver_id,
|
||||
const char *cache_dir_name_custom,
|
||||
@@ -167,8 +167,7 @@ void
|
||||
disk_cache_touch_cache_user_marker(char *path);
|
||||
|
||||
bool
|
||||
disk_cache_mmap_cache_index(void *mem_ctx, struct disk_cache *cache,
|
||||
char *path);
|
||||
disk_cache_mmap_cache_index(void *mem_ctx, struct disk_cache *cache);
|
||||
|
||||
void
|
||||
disk_cache_destroy_mmap(struct disk_cache *cache);
|
||||
|
||||
Reference in New Issue
Block a user