Blender V4.3
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
5#include "BLI_cache_mutex.hh"
6#include "BLI_task.hh"
7
8namespace blender {
9
10void CacheMutex::ensure(const FunctionRef<void()> compute_cache)
11{
12 if (cache_valid_.load(std::memory_order_acquire)) {
13 return;
14 }
15 std::scoped_lock lock{mutex_};
16 /* Double checked lock. */
17 if (cache_valid_.load(std::memory_order_relaxed)) {
18 return;
19 }
20 /* Use task isolation because a mutex is locked and the cache computation might use
21 * multi-threading. */
22 threading::isolate_task(compute_cache);
23
24 cache_valid_.store(true, std::memory_order_release);
25}
26
27} // namespace blender
volatile int lock
void ensure(FunctionRef< void()> compute_cache)
void isolate_task(const Function &function)
Definition BLI_task.hh:226