Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'intern/cycles/util/path.cpp')
-rw-r--r--intern/cycles/util/path.cpp56
1 files changed, 47 insertions, 9 deletions
diff --git a/intern/cycles/util/path.cpp b/intern/cycles/util/path.cpp
index 17cff2f2977..cb6b8d7a740 100644
--- a/intern/cycles/util/path.cpp
+++ b/intern/cycles/util/path.cpp
@@ -2,8 +2,11 @@
* Copyright 2011-2022 Blender Foundation */
#include "util/path.h"
+#include "util/algorithm.h"
+#include "util/map.h"
#include "util/md5.h"
#include "util/string.h"
+#include "util/vector.h"
#include <OpenImageIO/filesystem.h>
#include <OpenImageIO/strutil.h>
@@ -898,19 +901,54 @@ FILE *path_fopen(const string &path, const string &mode)
#endif
}
-void path_cache_clear_except(const string &name, const set<string> &except)
+/* LRU Cache for Kernels */
+
+static void path_cache_kernel_mark_used(const string &path)
{
- string dir = path_user_get("cache");
+ std::time_t current_time = std::time(nullptr);
+ OIIO::Filesystem::last_write_time(path, current_time);
+}
- if (path_exists(dir)) {
- directory_iterator it(dir), it_end;
+bool path_cache_kernel_exists_and_mark_used(const string &path)
+{
+ if (path_exists(path)) {
+ path_cache_kernel_mark_used(path);
+ return true;
+ }
+ else {
+ return false;
+ }
+}
- for (; it != it_end; ++it) {
- string filename = path_filename(it->path());
+void path_cache_kernel_mark_added_and_clear_old(const string &new_path,
+ const size_t max_old_kernel_of_same_type)
+{
+ path_cache_kernel_mark_used(new_path);
+
+ string dir = path_dirname(new_path);
+ if (!path_exists(dir)) {
+ return;
+ }
+
+ /* Remove older kernels within the same directory. */
+ directory_iterator it(dir), it_end;
+ vector<pair<std::time_t, string>> same_kernel_types;
+
+ for (; it != it_end; ++it) {
+ const string &path = it->path();
+ if (path == new_path) {
+ continue;
+ }
+
+ std::time_t last_time = OIIO::Filesystem::last_write_time(path);
+ same_kernel_types.emplace_back(last_time, path);
+ }
+
+ if (same_kernel_types.size() > max_old_kernel_of_same_type) {
+ sort(same_kernel_types.begin(), same_kernel_types.end());
- if (string_startswith(filename, name.c_str()))
- if (except.find(filename) == except.end())
- path_remove(it->path());
+ for (int i = 0; i < same_kernel_types.size() - max_old_kernel_of_same_type; i++) {
+ path_remove(same_kernel_types[i].second);
}
}
}