Blender V5.0
cache_mutex.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_cache_mutex.hh"
10#include "BLI_task.hh"
11
12namespace blender {
13
14void CacheMutex::ensure_impl(const FunctionRef<void()> compute_cache)
15{
16 if (cache_valid_.load(std::memory_order_acquire)) {
17 return;
18 }
19 std::scoped_lock lock{mutex_};
20 /* Double checked lock. */
21 if (cache_valid_.load(std::memory_order_relaxed)) {
22 return;
23 }
24 /* Use task isolation because a mutex is locked and the cache computation might use
25 * multi-threading. */
26 threading::isolate_task(compute_cache);
27
28 cache_valid_.store(true, std::memory_order_release);
29}
30
31} // namespace blender
volatile int lock
void isolate_task(const Function &function)
Definition BLI_task.hh:248