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:
authorJoseph Eagar <joeedh@gmail.com>2022-11-12 01:18:46 +0300
committerJoseph Eagar <joeedh@gmail.com>2022-11-12 01:18:46 +0300
commitc29795452cc71cb9f5a571a4aff0f593a2d7acaf (patch)
tree53a46bb77f3102c545f7e55d3344e310b3bf6116 /source/blender/blenlib/intern/cache_mutex.cc
parent9980fd0b8e1f3a07060316f28469f55a3f2fc0cd (diff)
parent03ccf37162d365f3fdc8d8cd0cd6e9ff314fec6e (diff)
Merge branch 'master' into temp-sculpt-roll-mappingtemp-sculpt-roll-mapping
Diffstat (limited to 'source/blender/blenlib/intern/cache_mutex.cc')
-rw-r--r--source/blender/blenlib/intern/cache_mutex.cc25
1 files changed, 25 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/cache_mutex.cc b/source/blender/blenlib/intern/cache_mutex.cc
new file mode 100644
index 00000000000..db474b1ef87
--- /dev/null
+++ b/source/blender/blenlib/intern/cache_mutex.cc
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "BLI_cache_mutex.hh"
+#include "BLI_task.hh"
+
+namespace blender {
+
+void CacheMutex::ensure(const FunctionRef<void()> compute_cache)
+{
+ if (cache_valid_.load(std::memory_order_acquire)) {
+ return;
+ }
+ std::scoped_lock lock{mutex_};
+ /* Double checked lock. */
+ if (cache_valid_.load(std::memory_order_relaxed)) {
+ return;
+ }
+ /* Use task isolation because a mutex is locked and the cache computation might use
+ * multi-threading. */
+ threading::isolate_task(compute_cache);
+
+ cache_valid_.store(true, std::memory_order_release);
+}
+
+} // namespace blender